locked
Is it possible to select multiple items from a combobox RRS feed

  • Question

  •  Is it possible to select multiple items from a ComboBox
    Wednesday, December 24, 2008 8:41 AM

Answers

  • Hi sadhik aboobaker,

    Based on the combobox’ properties,  it can deal with the current item selected, for the reason that it only shows one single line data. For example,  combobox.selectedIndex just gets or sets the index specifying the currently selected item. See msdn:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindex.aspx

     

    If you want to select multiple items, you may choose listbox.



    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Yichun Feng Monday, December 29, 2008 1:34 AM
    Thursday, December 25, 2008 10:44 AM
  • Hi Sadhik,

    For multiple items , put one ListBox on a FORM and try this ListBox example please.>>


    Regards,

    John

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
     
            'Set the SelectionMode to SelectionMode.MultiSimple  
            ' or to SelectionMode.MultiExtended >>  
            ListBox1.SelectionMode = SelectionMode.MultiSimple  
            For num As Integer = 1 To 9  
                ListBox1.Items.Add("Item" & num.ToString)  
            Next 
     
        End Sub 
     
        Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged  
     
            Dim myItems As ListBox.SelectedObjectCollection  
            myItems = ListBox1.SelectedItems  
            Dim sb As New System.Text.StringBuilder  
     
            For Each thing As Object In myItems  
                sb.Append(thing.ToString & ControlChars.NewLine)  
            Next 
     
            MessageBox.Show(sb.ToString)  
     
        End Sub 
    End Class 
     

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    • Marked as answer by Yichun Feng Monday, December 29, 2008 1:34 AM
    Sunday, December 28, 2008 5:04 AM

All replies

  • Hi sadhik aboobaker,

    Based on the combobox’ properties,  it can deal with the current item selected, for the reason that it only shows one single line data. For example,  combobox.selectedIndex just gets or sets the index specifying the currently selected item. See msdn:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindex.aspx

     

    If you want to select multiple items, you may choose listbox.



    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Yichun Feng Monday, December 29, 2008 1:34 AM
    Thursday, December 25, 2008 10:44 AM
  • Hi Sadhik,

    For multiple items , put one ListBox on a FORM and try this ListBox example please.>>


    Regards,

    John

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
     
            'Set the SelectionMode to SelectionMode.MultiSimple  
            ' or to SelectionMode.MultiExtended >>  
            ListBox1.SelectionMode = SelectionMode.MultiSimple  
            For num As Integer = 1 To 9  
                ListBox1.Items.Add("Item" & num.ToString)  
            Next 
     
        End Sub 
     
        Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged  
     
            Dim myItems As ListBox.SelectedObjectCollection  
            myItems = ListBox1.SelectedItems  
            Dim sb As New System.Text.StringBuilder  
     
            For Each thing As Object In myItems  
                sb.Append(thing.ToString & ControlChars.NewLine)  
            Next 
     
            MessageBox.Show(sb.ToString)  
     
        End Sub 
    End Class 
     

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    • Marked as answer by Yichun Feng Monday, December 29, 2008 1:34 AM
    Sunday, December 28, 2008 5:04 AM