Combo box controls can make your WPF application more user-friendly by allowing the user to make a selection from a list of items. Often, the first item the user is going to select is always the same one and this can cause user frustration. To avoid this problem, set the default value of the combo box control by suing the "SelectedIndex" property. This property sets the index specifying the currently selected item in the control.
- Skill level:
Other People Are Reading
Launch Microsoft Visual Studio. Click "New Project" from the left pane of your computer screen. Expand Other Languages, expand Visual C#, and click "Windows." Double-click "WPF Application" to create a new WPF project.
Double-click "ComboBox" from the Toolbox pane to add a new combo box control. Right-click the combo box and click "Properties" to open the properties window. Expand "Common" and scroll down to Items. Click the ellipsis to launch the Collection Editor window.
Click "Add" to add a new item and type "Item" next to "Content." Add a second item using the same technique and type "Item" next to "Content." Add a third item called "Item" and click "OK."
Right-click the grid window and click "Properties." Click the "Events" tab and scroll down to "Loaded." Double-click next to Loaded to create a grid-loaded event.
Type the following code to set the default value of the combo box as "Item:"
this.comboBox1.SelectedIndex = 1;
Press "F5" to run your program and view "Item" as the selected item in the combo box control.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for