The following quick start guide is intended to get you up and running with ComboBox for WPF. In this quick start, you'll create a new Visual Studio project with two C1ComboBox controls. The first control will be populated with a list of three items that, when clicked, will determine the list that appears in the second combo box.
You have completed the first step of the quick start by creating a WPF project and adding two C1ComboBox controls to it. In the next step, you'll add items to the first C1ComboBox control.
In the last step, you created a project and added two C1ComboBox controls to it. In this step, you will add three items to the first combo box.
Complete the following steps:
In this step, you added items to the first combo box. In the next step, you will add code to the project that will populate the second combo box with items when a user selects an item in the first combo box.
In the last step, you added items to the first combo box. In this step, you will add code to the project that will populate the second combo box according to the option the user selects in the first combo box.
Visual Basic Copy Code Imports System.Collections.Generic
C# Copy Codeusing System.Collections.Generic;
Visual Basic Copy Code 'Create List for Comedy selection Dim dropDownList_Comedy As New List(Of String)() dropDownList_Comedy.Add("Absolutely Fabulous") dropDownList_Comedy.Add("The Colbert Report") dropDownList_Comedy.Add("The Daily Show") dropDownList_Comedy.Add("The Office") 'Create List for Drama selection Dim dropDownList_Drama As New List(Of String)() dropDownList_Drama.Add("Breaking Bad") dropDownList_Drama.Add("Desperate Housewives") dropDownList_Drama.Add("Mad Men") dropDownList_Drama.Add("The Sopranos") 'Create List for Science Fiction selection Dim dropDownList_SciFi As New List(Of String)() dropDownList_SciFi.Add("Battlestar Galactica") dropDownList_SciFi.Add("Caprica") dropDownList_SciFi.Add("Stargate") dropDownList_SciFi.Add("Star Trek") 'Check for SelectedIndex value and assign appropriate list to 2nd combo box If Category.SelectedIndex = 0 Then Shows.ItemsSource = dropDownList_Comedy ElseIf Category.SelectedIndex = 1 Then Shows.ItemsSource = dropDownList_Drama ElseIf Category.SelectedIndex = 2 Then Shows.ItemsSource = dropDownList_SciFi End If
C# Copy Code //Create List for Comedy selection List<string> dropDownList_Comedy = new List<string>(); dropDownList_Comedy.Add("Absolutely Fabulous"); dropDownList_Comedy.Add("The Colbert Report"); dropDownList_Comedy.Add("The Daily Show"); dropDownList_Comedy.Add("The Office"); //Create List for Drama selection List<string> dropDownList_Drama = new List<string>(); dropDownList_Drama.Add("Breaking Bad"); dropDownList_Drama.Add("Desperate Housewives"); dropDownList_Drama.Add("Mad Men"); dropDownList_Drama.Add("The Sopranos"); //Create List for Science Fiction selection List<string> dropDownList_SciFi = new List<string>(); dropDownList_SciFi.Add("Battlestar Galactica"); dropDownList_SciFi.Add("Caprica"); dropDownList_SciFi.Add("Stargate"); dropDownList_SciFi.Add("Star Trek"); //Check for SelectedIndex value and assign appropriate list to 2nd combo box if (Category.SelectedIndex == 0) { Shows.ItemsSource = dropDownList_Comedy; } else if (Category.SelectedIndex == 1) { Shows.ItemsSource = dropDownList_Drama; } else if (Category.SelectedIndex ==2) { Shows.ItemsSource = dropDownList_SciFi; }
In the next step, you will run the project and observe the results of this quick start.
In the previous three steps, you created a WPF project with two combo boxes, added items to the first combo box, and wrote code that will populate the second combo box with items once an item is selected in the first combo box. In this step, you will run the project and observe the results of this quick start.
Complete the following steps:
Congratulations! You have completed the ComboBox for WPF quick start.