Reputation: 2910
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");
}
}
Upvotes: 0
Views: 356
Reputation:
You can just use the ListBox.SelectedIndex property...
public MyWindow()
{
InitializeComponent();
yourListBox.SelectedIndex = indexOfRed;
}
Upvotes: 1