Question Adding a single item to a combobox

greekman123

New member
Joined
Apr 4, 2011
Messages
2
Programming Experience
Beginner
Hi,

I'm new to vb.net and I have what probably is a simple question, but one that I am stuck on.

I'm trying to add a single item to a ca combo box at run time.

For example, a user selects a category from the first drop down box at run time, say "Admin", I want to add a single item to the combo box below it: Not applicable.

cboTest.Items.Clear()
cboTest.Items.Add("Not Applicable")

Any help would be appreciated.
 
I believe this is what you are thinking of:

VB.NET:
Expand Collapse Copy
Private Sub cboCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCategory.SelectedIndexChanged
        Select Case cboCategory.SelectedItem
            Case "Admin"
                'If the selected item is "Admin" then clear the list and add the "Not Applicable" item
                cboTest.Items.Clear()
                cboTest.Items.Add("Not Applicable")
            Case "Other"
                'If the selected item is "Other" then clear the list and add item's 1, 2, and 3.
                ComboBox1.Items.Clear()
                ComboBox1.Items.Add("Item1")
                ComboBox1.Items.Add("Item2")
                ComboBox1.Items.Add("Item3")
        End Select
    End Sub

Hope this helps, you will have to replace the different cases with your own categories and add your own items. (To get to the "SelectedIndexChanged" event, double click on the category ComboBox in the designer.

-Josh
 
Back
Top