ComponentOne Input for WinForms
Using the C1Input Controls / C1Input Controls / C1ComboBox Control Overview / Populating C1Combbox with Data Using the SelectedIndexChanged Event
In This Topic
    Populating C1Combbox with Data Using the SelectedIndexChanged Event
    In This Topic

    To populate the C1ComboBox with data once a specific index in the combo box has been selected, use the SelectedIndexChanged event like the following:

    1. Add two C1ComboBoxes on the Form.
    2. In the first C1ComboBox add the items line by line in the String Collection Editor so it appears like the following:

     stringcollectioneditor_combobox

    1. Double click on the SelectedIndexChanged event in the C1ComboBox Properties window to create an event handler for the SelectedIndexChanged event.
    2. Add the following code to the SelectedIndexChanged event:

    To write code in Visual Basic

    Title Text
    Copy Code

     Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        c1ComboBox2.Items.Clear()
        If c1ComboBox1.SelectedIndex.ToString() = "1" Then

            c1ComboBox2.Items.Add("You selected the second item.")
        Else

            c1ComboBox2.Items.Add("You did not select the second item.")
        End If
    End Sub

    To write code in C#

    C#
    Copy Code

     private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                c1ComboBox2.Items.Clear();
                if (c1ComboBox1.SelectedIndex.ToString() == "1")
                {
                    c1ComboBox2.Items.Add("You selected the second item.");
                  
                }
                else
                {
                    c1ComboBox2.Items.Add("You did not select the second item.");

                }
            }

    1. Run your project and select the first index or second item, "Orlando" in the first C1ComboBox.
    2. Click on the dropdown button in the second C1ComboBox and notice the items were added to the dropdownlist based on what you added in the SelectedIndexChanged event.

    combo-box

    See Also