You need to have a
SelectionChanged
event handler :
XAML code :
<combobox height="23" horizontalalignment="Left" margin="12,41,0,0" name="comboBox1" verticalalignment="Top" width="120" selectionchanged="comboBox1_SelectionChanged">
<comboboxitem content="A" />
<comboboxitem content="B" />
<comboboxitem content="C" />
</combobox>
<combobox height="23" horizontalalignment="Left" margin="12,84,0,0" name="comboBox2" verticalalignment="Top" width="120" />
Code behind :
in
Loaded
event handler (of your Window or Page or User Control) :
comboBox1.SelectedIndex = 0;
and the
SelectionChanged
event handler :
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBox2 == null)
return;
switch (comboBox1.SelectedIndex)
{
case 0:
comboBox2.ItemsSource = new List<int> { 0, 1, 2 };
break;
case 1:
comboBox2.ItemsSource = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
break;
case 2:
comboBox2.ItemsSource = new List<int> { 9 };
break;
}
comboBox2.SelectedIndex = 0;
}
Hope it helps.