我有一个包含两个项目的组合框。I also have a button that opens a new form when one of these items are selected. 但是,如果没有选择任何项目,则会出现异常(空指针)。我已尝试(无济于事)捕获此异常并显示一个提示用户选择其中一项的 mbox。
以下是按钮单击的代码:
if (labelGrid.Text == "Member" && cbTable.SelectedItem.ToString().Equals("Workout"))
{
string name;
string ss;
foreach (DataGridViewRow item in this.dtGrid1.SelectedRows)
{
ss = dtGrid1.CurrentCell.Value.ToString();
name = dtGrid1.SelectedCells[1].Value.ToString();
BookMemberWorkout bmw = new BookMemberWorkout(ss, name);
bmw.Label2.Text = ss;
bmw.Label1.Text = name;
bmw.ShowDialog();
}
}