Basic Library for WPF and Silverlight | ComponentOne
WPF and Silverlight Edition Basic Library / Combo Box / ComboBox Features / ComboBox Items / Selecting Items
In This Topic
    Selecting Items
    In This Topic

    The SelectedIndex property determines which item is selected in a drop-down list. The SelectedIndex is based on a zero-based index, meaning that 0 represents the first C1ComboBoxItem, 1 represents the second C1ComboBoxItem, and so on. In the image below, the SelectedIndex is set to 2, which selects the third C1ComboBoxItem.

     

    To set a selected item, add SelectedIndex="0" to the <c1:C1ComboBoxItem> tag so that the markup resembles the following:

    XAML
    Copy Code
    <c1:C1ComboBoxItem Content="C1ComboBoxItem1" SelectedIndex="1">
    

     

    Complete the following steps:

    1. Open the MainWindow.xaml.cs or the MainPage.xaml.cs page (or the MainWindow.xaml.vb page for Visual Basic).
    2. Add the following code beneath the InitializeComponent() method:
    Visual Basic
    Copy Code
    C1ComboBoxItem1.SelectedIndex = 1
    

    C#
    Copy Code
    c1ComboBoxItem1.SelectedIndex = 1;
    
    1. Run the program.

    Complete the following steps:

    1. Select the C1ComboBox control.
    2. In the Properties window, set the SelectedIndex property to "1" so that the second C1ComboBoxItem will be selected.