tags:

views:

74

answers:

1

Hi, I have a System.Windows.Control.ListBox, and I would like to select a specific index of it. For example, my listbox is red, white, and blue, and after I read an object/file, I want to select red as the window appears. What is the best way to do that?

public partial class MyWindow :  System.Windows.Window
     {
        public MyWindow()
         {
             InitializeComponent();
             System.Windows.Control.ListBox MyListBox= (ListBox)this.FindName("myListBox");
         } 
     }
+1  A: 

You can just use the ListBox.SelectedIndex property...

public MyWindow()
{
    InitializeComponent();
    yourListBox.SelectedIndex = indexOfRed;
}
Chalkey