Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私のComboBoxでは、ユーザーがクリックして項目を選択する前に、このフィールドは空白になっています。したがって、ユーザーがComboBoxをクリックしないと、空のままになります。ComboBoxが空かどうかを確認するにはどうすればよいですか?
まだアイテムが選択されていないため、このコードはエラーになります。
if( ComboBox.SelectedItem.ToString().Equals("") ) { //do something }
if( ComboBox.SelectedItem == null ) { // do something }
ComboBox.SelectedItems.Count
これは機能するはずです:P選択したアイテムをカウントします。その数が0の場合、アイテムは選択されません。
if( ComboBox.SelectedIndex == -1 )