When using a ComboBox bound to a multi-column data source, you may want to display additional information (like a "Description" field) that isn't part of the main display text. You need a way to show these tooltips both when a user hovers over items in the dropdown list and when a specific item is selected while the control is closed.
Solution
To display tooltips for dropdown items, enable the ShowTooltip property on the ComboBox and handle the TooltipShowing event. Inside this event, you can set e.Text to the value of your description column. If your ItemsDataSource is a BindingSource, ensure you cast it correctly to access the underlying DataTable or data collection to retrieve the correct row's data.
To show a tooltip for the selected item when the ComboBox is closed, use a SuperTooltip component. By handling the SelectedIndexChanged event, you can dynamically update the SuperTooltip text to match the description of the currently selected record. This ensures the user always has access to the extended metadata regardless of the control's state.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
C1ComboBox1.DropDownStyle = C1.Win.C1Input.DropDownStyle.DropDownList
C1ComboBox1.TextDetached = True
C1ComboBox1.ItemsDataSource = New BindingSource(GetDataSource(), Nothing)
C1ComboBox1.ItemsDisplayMember = "Item"
C1ComboBox1.ItemsValueMember = "Item"
C1ComboBox1.ShowTooltip = True
End Sub
Private Sub C1ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles C1ComboBox1.SelectedIndexChanged
If C1ComboBox1.SelectedIndex <> -1 Then
'cast the ItemsDataSource to a BindingSource and access the DataTable
Dim dt As DataTable = TryCast(TryCast(C1ComboBox1.ItemsDataSource, BindingSource).DataSource, DataTable)
'set the tooltip for combobox according to selected item
superTooltip.SetToolTip(C1ComboBox1, dt.Rows(C1ComboBox1.SelectedIndex).ItemArray(2).ToString())
End If
End Sub
Private Sub C1ComboBox1_TooltipShowing(sender As Object, e As C1.Win.C1Input.TooltipShowingEventArgs) Handles C1ComboBox1.TooltipShowing
'cast the ItemsDataSource to a BindingSource and access the DataTable
Dim dt As DataTable = TryCast(TryCast(C1ComboBox1.ItemsDataSource, BindingSource).DataSource, DataTable)
'get the tooltip value from the description column
e.Text = dt.Rows(e.Index).ItemArray(2).ToString()
End Sub
Private Function GetDataSource() As Object
Dim dt As New DataTable()
dt.Columns.Add("Id")
dt.Columns.Add("Item")
dt.Columns.Add("Description")
dt.Rows.Add(1, "Item1", "Description1")
dt.Rows.Add(2, "Item2", "Description2")
dt.Rows.Add(3, "Item3", "Description3")
Return dt
End Function