PDA

View Full Version : Solved: Mouse over a particular column in ListView to display a message



lionne
04-26-2013, 12:23 AM
hi

Is there a way to display a short message, when pointing with a mouse on a particular item (or even better on header) of a column in a ListView Control? I am using a Form Activate event, where I populate the ListView Control:


Private Sub UserForm_Activate()

Dim wb As Workbook
Dim lc As Worksheet
Dim Row As Integer

Set wb = Excel.ActiveWorkbook
Set lc = wb.Sheets("LogCase")

Dim li As ListItem
Dim liSI As ListSubItem

'populate the list view
With Review_Logical.lsv_tclist

.ColumnHeaders.Add , , "ID"
.ColumnHeaders(1).Width = 25
.ColumnHeaders.Add , , "Test Case Name"
.ColumnHeaders(2).Width = 200
.ColumnHeaders.Add , , "New Parlist Field(s)"
.ColumnHeaders(3).Width = 80

.FullRowSelect = True
.LabelEdit = lvwManual
.CheckBoxes = False
.HideColumnHeaders = False
.View = 3
.Gridlines = True
.MultiSelect = True

For Row = 2 To tc_num 'tc_num is integer, its value is omitted here

Set li = .ListItems.Add(, , lc.Cells(Row, 1).Value)
li.SubItems(1) = lc.Cells(Row, 2).Value

'...

Next

End With

End Sub

mikerickson
04-27-2013, 01:31 AM
I'm not familiar with the ListView control. Its not supported on my Mac.

If it is like the other controls, it should have a ControlToolTip property that will display a message if the mouse hovers on the control.

The MouseMove event's x and y values let you know what the mouse is pointing at.

lionne
05-02-2013, 01:13 AM
Hi Mike,

somehow I haven't found any example for MouseOver for a VBA-Excel ListView Control. Here is what I have tried:


Private Sub Review_Logical_ItemMouseHover(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long) 'Review_Logical is the name of the UserForm

Dim lsv_tclist As ListView
Dim li As ListItem

Set tclist = Me.lsv_tclist.Object
Set li = lsv_tclist.HitTest(x, y)

If li.index = 2 Then 'here I want the message to appear only if the mouse hovers the second column

Me.lsv_tclist.ControlTipText = "Warning: The AFT used for the marked logical test case " & vbNewLine & _
" is not activated on this database"

End If

End Sub

Does anyone have ideas?

mancubus
05-02-2013, 02:06 AM
here is a working example....

http://www.vbforums.com/showthread.php?248562-Mouseover-Listview-Tooltip-SOLVED


Private Sub lstIndex_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lstItem As ListItem
Set lstItem = lstIndex.HitTest(x, y)
If lstItem Is Nothing Then
lstIndex.ToolTipText = ""
Else
lstIndex.ToolTipText = lstItem.Text & " - " & lstItem.SubItems(1)
End If
End Sub

lionne
05-02-2013, 03:41 AM
I am thick today... I cannot get it work...

I put this sub right after the UserForm_Activate() sub, right?


Private Sub lsv_tclist_MouseMove(Button As Integer, Shift As Integer, _
x As Single, y As Single) 'lsv_tclist is the name of my ListView, but it crashes here, saying "Declaration of this procedure doesn't correspond to the description of Event or Procedure with the same name"

Dim lstItem As ListItem
Set lstItem = lsv_tclist.HitTest(x, y)

If lstItem Is Nothing Then
lsv_tclist.TooltipText = "bla bla"
Else
lsv_tclist.TooltipText = lsv_tclist.text & " - " & lsv_tclist.SubItems(1)
End If

End Sub

What am I doing wrong?

mancubus
05-02-2013, 06:27 AM
download the file from below link for a working example...

maybe it will help you solve your problem.

http://www.xlplus.de/vbaCorner/MultiLineTooltip/MultiLineTooltip.asp

lionne
05-06-2013, 01:09 AM
hey mancubus,

that's great! That did the job, you're awesome! Thank you!

mancubus
05-06-2013, 03:59 AM
you are welcome.
thanks to google and xlplus.de

can you please mark the thread as solved from "thread tools" dropdown which is just above the first message.