Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I have a combo box within my windows form application, I want to be able to select many items of combobox, anyone there have an idea? Please guide me in a very easy way!!!
Posted

Make a custom control or a user control with an instance of a TextBox and an instance of a ListBox in it. The System.Windows.Forms.ListBox can work with multiple selection. Inside this custom control, simulate behavior similar to the combo box, only with multiple selection, provide similar interface to the user of the control. This is a pretty usual approach, by the way.

Please see:

http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.aspx[^].

This are the selection modes of System.Windows.Forms.ListBox:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectionmode.aspx[^].

See also:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx[^].

—SA
 
Share this answer
 
VB
Private Sub InitializeMyListBox()
   ' Add items to the ListBox.
   listBox1.Items.Add("A")
   listBox1.Items.Add("C")
   listBox1.Items.Add("E")
   listBox1.Items.Add("F")
   listBox1.Items.Add("G")
   listBox1.Items.Add("D")
   listBox1.Items.Add("B")

   ' Sort all items added previously.
   listBox1.Sorted = True

   ' Set the SelectionMode to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended

   ' Select three initial items from the list.
   listBox1.SetSelected(0, True)
   listBox1.SetSelected(2, True)
   listBox1.SetSelected(4, True)

   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub

Private Sub InvertMySelection()

   Dim x As Integer
   ' Loop through all items the ListBox.
   For x = 0 To listBox1.Items.Count - 1

      ' Determine if the item is selected.
      If listBox1.GetSelected(x) = True Then
         ' Deselect all items that are selected.
         listBox1.SetSelected(x, False)
      Else
         ' Select all items that are not selected.
         listBox1.SetSelected(x, True)
      End If
   Next x
   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub
 
Share this answer
 
Comments
naserdtr123 26-Mar-12 1:53am    
Dear Rakesh,
as i am a beginner i do wanna know how this works? Please lemme know where to start? I just need to copy paste or something needed to be done by me? Regards
kishore Rajendran 26-Mar-12 2:26am    
Please use listbox
fjdiewornncalwe 4-Apr-13 15:41pm    
Plagiarized: source

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900