-
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:
Private Sub lbxRecCust_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbxRecCust.SelectedIndexChanged
'Dim srch As String
Dim sqlsrch As String
Dim dssrch As New DataSet
Dim dasrch As New Odbc.OdbcDataAdapter
Try
sqlsrch = "SELECT * FROM partdefinition WHERE LOWER(customername) LIKE '%" & CType(lbxRecCust.SelectedItem, DataRowView).Item("customername").ToString.ToLower & "%' ORDER BY partnumber ASC;"
dasrch = New Odbc.OdbcDataAdapter(sqlsrch, con)
dasrch.Fill(dssrch, "partdefinition")
Catch ox As Odbc.OdbcException
MsgBox(ox.Message)
Exit Sub
End Try
With lbxRecPart
.DataSource = dssrch.Tables("partdefinition")
.DisplayMember = "partnumber"
End With
'MessageBox.Show("There are no parts associated with this customer", "No Parts", MessageBoxButtons.OK)
End Sub
-
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.
-
Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!
Anybody? This can't be THAT difficult.
-
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:
dim toolTip as String = dataset.fieldOfTheTextYouWantDisplayed
ToolTip1.SetToolTip(Me.ListBox1, toolTip)
then, when you did a mouseHover, the toolTip would then show but that wouldnt really be efficient.
-
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
-
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?
-
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:
Private Sub lbxRecPart_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbxRecPart.MouseMove
Try
ToolTip1.SetToolTip(lbxRecPart, dssrch.Tables("partdefinition").Rows(lbxRecPart.IndexFromPoint(lbxRecPart.PointToClient(lbxRecPart.MousePosition))).Item("PartDescription"))
Catch ex as Exception
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.
-
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.
-
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:
Dim dtSrch as New DataTable
Then after you pull the dataset you throw a table copy into the mix, like so...
VB Code:
dasrch.Fill(dssrch, "partdefinition") 'old code
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:
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.
-
Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!
Genius, pure genius...works like a charm.
-
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 :sick:
-
Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY!
Yes, it does. Works even better than a plain old tooltip.
-
Re: Here's a fun one...ToolTips, ListBoxes, DataSets..Oh MY! [RESOLVED,THIS BOARD ROCKS!]
yes, this board DOES rock!!