我正在尝试为 vb.Net 中的组合发出错误消息

I'm trying to make an error message for the combo in vb.Net

If (String.IsNullOrEmpty(YearBox.Text)) Then
   MessageBox.Show("Please select a year group")
End If

上面的代码显示了我所做的,我试图确保当用户提交他们的详细信息并且不 select 弹出消息的年份组(它正确地执行) .但是当他们 select 参加了一个年级组时,该消息仍然出现,因此不允许他们提交他们的详细信息。

如果您想检查用户是否选择了某些内容,请使用此语法

If YearBox.SelectedIndex < 0 Then ' Nothing Selected
    MessageBox.Show("Please select a year group")
End If