指定した項目が選択されているかどうかを調べるには、Items プロパティに選択状態を調べる項目のインデックスを指定し、 IsSelected プロパティを参照します。
IsSelected プロパティの値が Trueであれば、その項目は選択状態にあります。
下記は、[2番目の選択状態]ボタンがクリックされたときに、2番目の項目(インデックスが1)の選択状態を調べてメッセージボックスに表示する例です。
VBの例
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click If DirectCast(ComboBox1.Items(1), ListBoxItem).IsSelected Then MessageBox.Show("選択されています") Else MessageBox.Show("選択されていません") End If End Sub
C#の例
private void button1_Click(object sender, RoutedEventArgs e) { if (((ComboBoxItem)comboBox1.Items[1]).IsSelected) MessageBox.Show("選択されています"); else MessageBox.Show("選択されていません"); }