hello.
i need help with combobox in vb.net.
i try to add several columns in the combo,so i want when i select one item in the combo (this item is composed from 3 words for example),so i want the text in the combobox not to be composed from these 3 words but from one of these 3 word.
this is what i need.
so to test the combobox,i tried when i select an item in the combobox (what ever this item) to set manually the text in the combo and that is the impossible,so i noticed that when i select an item in the combo box ,it's been selected in the combo so it's impossible to change the selection so i tried :combobox1.SelectionLength = -1 but it throw an exception and i fail.and i tried everything i can and no result.
so i know the key is to unselect the selection in the combo,then set manually the text,it's like to click in the textarea of the combo to unselect the item selected.
so i need your experience.
thank you for help.

Dani AI

Generated

Quick clarification and practical routes from the discussion between and .

If the ComboBox is set to the non-editable style (DropDownList) then assigning ComboBox.Text will not change what the control displays — the control always shows the selected item. That explains why SelectedIndex = -1 plus Text = "..." produced a blank box for . Set the control to an editable style if you need to show arbitrary text:

ComboBox1.DropDownStyle = ComboBoxStyle.DropDown

Also avoid mutating SelectedIndex inside SelectedIndexChanged without a guard; changing the selection programmatically can re-enter the event. Use SelectionChangeCommitted for user selections, use a boolean reentrancy flag, or do the assignment via BeginInvoke so the UI thread finishes the current event first.

Three practical ways to achieve a multi-column dropdown while controlling which column becomes the displayed text:

  • Owner-draw the ComboBox and draw multiple columns yourself in DrawItem. Keep items as objects (with properties for each column) and draw the columns using fixed widths or measured strings. See Microsoft guidance on owner-drawn ComboBox for details: .

  • Replace the dropdown with a proper multi-column control (ListView or DataGridView) hosted inside a popup. A common pattern is hosting the control in a ToolStripDropDown/ToolStripControlHost, show it on arrow click, and copy the chosen row’s specific column into the combo’s text. ToolStripControlHost docs: ToolStripControlHost.

  • The overlay TextBox trick mentioned by works for a read-only look-and-feel if you only need to display a single field while keeping the dropdown behavior for selection.

Troubleshooting tips: measure column widths for owner-draw, handle focus/closing when hosting custom popups, and prefer SelectionChangeCommitted to detect user picks. These patterns avoid the blank-text problem and give full control over which column appears in the combobox text.

Recommended Answers

All 5 Replies

This is what you need, it's a multi-column combobox.

And for your problem with unselecting a selected item, use combobox1.SelectedIndex = -1 .

thank you ,but first iconCombobox is not defined and i add the dll from the site but it doesn't work and i will try again.
and about combobox1.SelectedIndex = -1 ,for example:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 10
ComboBox1.Items.Add("daniweb " & i)
Next

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

ComboBox1.SelectedIndex = -1
ComboBox1.Text = "Oxiegen"

End Sub

it doesn't work ,all i acheive that a blan combobox.
about the combo ,i had a project on university that i need combo ,so my solution that to add 2 combo one on another and play with visibility ,but i don't accept that ,i want to act like real programmer so that's my solution 2 combo and i had second solution a timer tick ,but if i had 10 combo => 10 timer also it isn't a good solution so after hard working yes i need like iconcombo posted in your link but it's a custom control that others create it ,so i want a solution in the standard combobox.
again thank you.

Unfortunatily, the standard combobox does not support true multiple columns. You have to go custom for that.

There is one solution that I found a while back ago, when I was researching readonly comboboxes.
It involves one combobox and one textbox.
Put the textbox on top of the combobox, set the width to cover all of the combobox except the dropdown-arrow, and set it's visibility to false.

Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
   TextBox1.Visible = False
End Sub

Privte Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
   If ComboBox1.SelectedIndex > -1 Then
      TextBox1.Visible = True
      TextBox1.Text = ComboBox1.SelectedItem.ToString().SubString(0, ComboBox1.SelectedItem.ToString().IndexOf("<delimiter>"))
   End If
End Sub

yes it's another solution thank you,and unfortunatily the multiple columns combobox it's very powerful and it's a must.so the custom combobox is the solution and this the first time after your reply that i know that we can add custom controls so thank you very much.

Glad to be of help. :)
Please mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.