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

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

    1. Add two C1ComboBoxes on the Form.
    2. Add the string, "Pittsburgh", to the first C1ComboBox using the String Collection Editor.
    3. Double click on the SelectedItemChanged event in C1ComboBox Properties window to create an event handler for the SelectedItemChanged event.
    4. Add the following code to the SelectedIndexChanged event:

    To write code in Visual Basic

    Visual Basic
    Copy Code

     Private Sub comboBox1_SelectedItemChanged(sender As Object, e As EventArgs)
        c1ComboBox2.Items.Clear()
        If c1ComboBox1.SelectedItem.ToString() = "Pittsburgh" Then
            c1ComboBox2.Items.Add("Pittsburgh is known as the Steel City and the City of Bridges.")
            c1ComboBox2.Items.Add("Pittsburgh has 446 Bridges")
        Else

            c1ComboBox2.Items.Add("You did not select Pittsburgh.")
        End If
    End Sub

    To write code in C#

    C#
    Copy Code
     private void comboBox1_SelectedItemChanged(object sender, EventArgs e)
            {
                c1ComboBox2.Items.Clear();
                if (c1ComboBox1.SelectedItem.ToString() == "Pittsburgh")
                {
                    c1ComboBox2.Items.Add("Pittsburgh is known as the Steel City and the City of Bridges.");
                    c1ComboBox2.Items.Add("Pittsburgh has 446 Bridges");
                }
                else
                {
                    c1ComboBox2.Items.Add("You did not select Pittsburgh.");
                   
                }
            }
    1. Run your project and select Pittsburgh 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 SelectedItemChanged event.

    combo-box

    See Also