How to Set the Default Value for the WPF ComboBox

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Set the Default Value for the WPF ComboBox
Add items to a combo box in a WPF application. (Medioimages/Photodisc/Photodisc/Getty Images)

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:
Moderate

Other People Are Reading

Instructions

  1. 1

    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.

  2. 2

    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.

  3. 3

    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."

  4. 4

    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.

  5. 5

    Type the following code to set the default value of the combo box as "Item:"

    this.comboBox1.SelectedIndex = 1;

  6. 6

    Press "F5" to run your program and view "Item" as the selected item in the combo box control.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.