Results 1 to 13 of 13

Thread: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY! [RESOLVED,THIS BOARD ROCKS!]

  1. #1

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY! [RESOLVED,THIS BOARD ROCKS!]

    One ListBox (customer) contains data from a database, another ListBox (part number) gets filled when an item in the customer ListBox is clicked (SelectedIndexChanged).

    What I want to do, is display a ToolTip containing the Part Description (another field in the partdefinition table, which is already in the dataset) when hovering over the partnumber in the second ListBox.

    Here's the event that puts the part numbers in the second ListBox based on the selected customer from the first:
    VB Code:
    1. Private Sub lbxRecCust_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbxRecCust.SelectedIndexChanged
    2.  
    3.         'Dim srch As String
    4.         Dim sqlsrch As String
    5.         Dim dssrch As New DataSet
    6.         Dim dasrch As New Odbc.OdbcDataAdapter
    7.  
    8.         Try
    9.             sqlsrch = "SELECT * FROM partdefinition WHERE LOWER(customername) LIKE '%" & CType(lbxRecCust.SelectedItem, DataRowView).Item("customername").ToString.ToLower & "%' ORDER BY partnumber ASC;"
    10.             dasrch = New Odbc.OdbcDataAdapter(sqlsrch, con)
    11.             dasrch.Fill(dssrch, "partdefinition")
    12.         Catch ox As Odbc.OdbcException
    13.             MsgBox(ox.Message)
    14.             Exit Sub
    15.         End Try
    16.  
    17.         With lbxRecPart
    18.             .DataSource = dssrch.Tables("partdefinition")
    19.             .DisplayMember = "partnumber"
    20.         End With
    21.  
    22.         'MessageBox.Show("There are no parts associated with this customer", "No Parts", MessageBoxButtons.OK)
    23.  
    24.     End Sub
    Last edited by milkmood; Jun 16th, 2005 at 11:12 AM.
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  2. #2

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    I didn't think I could stump you guys, but . . . hmmm . . . maybe I did.
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  3. #3

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    Anybody? This can't be THAT difficult.
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    not sure of a way to show the toolTip on MouseHover() but you can SET the toolTip when the selected index changes like this:
    VB Code:
    1. dim toolTip as String = dataset.fieldOfTheTextYouWantDisplayed
    2. ToolTip1.SetToolTip(Me.ListBox1, toolTip)
    then, when you did a mouseHover, the toolTip would then show but that wouldnt really be efficient.

  5. #5
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    Hi,

    You can use the Item.rectangle to figure out which item you have, and then stick in the tooltip as Andy suggests.

    HTH

    zaza

  6. #6

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    I tried the first option, and can't convert dataset to string no matter how much I try and call just that one field (description). Could you expound on the rectangle option?
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  7. #7
    New Member
    Join Date
    Mar 2005
    Posts
    7

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    This should work for you. Andy was close with the MouseHover option. I would use Mouse move, as follows. I'm assuming the name ToolTip1 for the tool tip control,


    VB Code:
    1. Private Sub lbxRecPart_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbxRecPart.MouseMove
    2. Try
    3.         ToolTip1.SetToolTip(lbxRecPart, dssrch.Tables("partdefinition").Rows(lbxRecPart.IndexFromPoint(lbxRecPart.PointToClient(lbxRecPart.MousePosition))).Item("PartDescription"))
    4.  
    5. Catch ex as Exception
    6. End Try

    The empty Catch is neccessary because if you move your mouse over an empty area of the Listbox, the lbxRecPart.IndexFromPoint will return a -1, which is not a valid datatable row index and will throw an exception, which I wanted to ignore.

    I believe this will work for you. I have does similar tooltips from a dataset except mine was in a tree view.
    Last edited by KentDMc; Jun 16th, 2005 at 10:20 AM. Reason: Corrected name of listbox

  8. #8

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    Wow, that's much closer. Now the problem is, the dssrch dataset is private in another routine (the one above). If I put it up in the public class before form load, it messes a bunch of things up. How do I use that same dataset in this routine? I can pull another dataset of the same data for this routine, but efficiency would start to be lost.
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  9. #9
    New Member
    Join Date
    Mar 2005
    Posts
    7

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    Not knowing why you can't make it a global dataset makes my answer a little "iffy" (Most likely you are have several procedural delcarations using the same dssrch name). If I were you, I would declare a global datatable, for instance

    VB Code:
    1. Dim dtSrch as New DataTable

    Then after you pull the dataset you throw a table copy into the mix, like so...
    VB Code:
    1. dasrch.Fill(dssrch, "partdefinition") 'old code
    2.      dtSrch = dssrch.Tables("partdefinition").Copy

    That way the information from that table is always available if you every need it, then the tool tip deal becomes like this

    VB Code:
    1. ToolTip1.SetToolTip(lbxRecPart, dtSrch.Rows(lbxRecPart.IndexFromPoint(lbxRecPart.PointToClient(lbxRecPart.MousePosition))).Item("PartDescription"))

    True that saving the entire datatable in memory is perhaps resource wasting. You could polulate an array with the PartDescription information and grab the tool tip text from there, or you could create another invisible ListBox with datasource and datamember information pointing to PartDescription information or you could . . . you get the picture. I think the table copy is just easier and allows you to access the table any time you want.
    Last edited by KentDMc; Jun 16th, 2005 at 12:03 PM. Reason: Spelling mistakes

  10. #10

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    Genius, pure genius...works like a charm.
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  11. #11
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    does using the mouseMove event cause the tooltip to move along with the cursor? I've been trying to get that action to work for a while now

  12. #12

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!

    Yes, it does. Works even better than a plain old tooltip.
    When I say 'jump', don't waste time asking 'how high?'.

    Just a poor, dumb wanna-be programmer.

  13. #13
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY! [RESOLVED,THIS BOARD ROCKS!]

    yes, this board DOES rock!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width