how can I set a tooltip for each item in a listbox control?
Printable View
how can I set a tooltip for each item in a listbox control?
I don't think so but you can change the one for the list dynamically with each item selected.
hmm weirdness I thought it was easy:DQuote:
Originally posted by Edneeis
I don't think so but you can change the one for the list dynamically with each item selected.
well I want to have it whenever the mouse hovers over an item. I guess I have to show the tooltip manually, kinda inefficient I guess:(
I didn't think it was especially tricky... This is a bit more than you seem to be asking for (I pull my tip strings from a dataset for the app I cut this from) but the principle would be the same for whatever method you want to store your tip text:
VB Code:
Private Sub lvwItems_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles lvwItems.SelectedIndexChanged SetToolTip() End Sub Private Sub SetToolTip() If lvwItems.SelectedItems.Count > 0 Then 'Go get whole record for selected item Dim strTip As String Dim objRow As DataRow = dsData.Tables("SomeTable").Rows.Find(lvwItems.SelectedItems(0).Text) strTip = lvwItems.SelectedItems(0).Text If objRow("Comment") <> "" Then strTip += ControlChars.CrLf + "Comment: " + objRow("Comment") End If tipMain.SetToolTip(lvwItems, strTip) End If End Sub
I guess if you wanted to get more fancy you could set an event handler for MouseHover and see what's under the mouse? This was good enough for me though.
also since ToolTip.SetToolTip expects a control as an input, and ListViewItem is not a control, I don't believe you can set separate tooltips for each listview item, as Edneeis says you probably have to set it for each item you are looking at.
well I've seen it done in programs, so it can be done:D
I'm a lil busy... I have to find some free time and see if I can do it for each list item or not
thanks for the replies