?
Solved

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

Posted on 2006-05-04
7
Medium Priority
?
1,328 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:IvanHowarth
7 Comments
 
LVL 6

Assisted Solution

by:the_paab
the_paab earned 400 total points
ID: 16604360
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
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 16604534
MyToolTip.SetToolTip(MyListBox, MyListBox.Items(index).ToString())
0
 

Author Comment

by:IvanHowarth
ID: 16604786
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 96

Accepted Solution

by:
Bob Learned earned 1600 total points
ID: 16604805
MyToolTip.SetToolTip(MyListBox, CType(MyListBox.Items(index), DataRowView)("Column name goes here").ToString())

Bob
0
 

Author Comment

by:IvanHowarth
ID: 16604957
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16604991
Something along these lines:

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

Bob
0
 

Author Comment

by:IvanHowarth
ID: 16605147
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question