How do you set a tooltip to different listbox items in vb.net when bound to a dataView?

I have a listbox, it's data source is a dataview (bound to a data table). The classic problem: how do I get my tooltip to show individual items?

This following code only applies to the controls own collection of Items as it throws a System.InvalidCastException: "Cast from type 'DataRowView' to type 'String' is not valid"

Private Sub MyListBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyListBox.MouseMove
        Static lastIndex As Integer = -1
        Dim index As Integer = MyListBox.IndexFromPoint(MyListBox.PointToClient(Cursor.Position))
        If index <> ListBox.NoMatches Then
            If index <> lastIndex Then
                lastIndex = index
                MyToolTip.SetToolTip(MyListBox, CStr(MyListBox.Items(index)))
            End If
        End If
    End Sub

How do I alter it accordingly?
IvanHowarthAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the_paabCommented:
I think this way it should read column with index 0 from listobox item (as DataRowView) with "index":

MyToolTip.SetToolTip(MyListBox, CStr(MyListBox.Items(index)(0)))

0
Fahad MukhtarDistinguished EngineerCommented:
MyToolTip.SetToolTip(MyListBox, MyListBox.Items(index).ToString())
0
IvanHowarthAuthor Commented:
paab: yours works, but I have turn off option strict ("Option strict disallows late binding"), which I don't want to. Is there a way of keeping it on?


Desp: your option just feeds the tooltip with the string "System.Data.DataRowView" for every item.
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Bob LearnedCommented:
MyToolTip.SetToolTip(MyListBox, CType(MyListBox.Items(index), DataRowView)("Column name goes here").ToString())

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IvanHowarthAuthor Commented:
Bob, it works.

Thanks, to you all.

Another quick one - how do you get a multi-row tooltip? It would really be practical if I could show the values of two dataview columns.

I'll share the points upon this answer.
0
Bob LearnedCommented:
Something along these lines:

    Me.ToolTip1.SetToolTip(Me.PictureBox1, "This is a" & vbLf & "test")

Bob
0
IvanHowarthAuthor Commented:
Brilliant

The correct line for the multiline tooltip is:

MyToolTip(MyListBox, CType(MyListBox.Items(index), DataRowView)("Column1").ToString() + vbLf + CType(MyListBox.Items(index), DataRowView)("Column2").ToString())

Thanks all again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.