Когда пользователь нажимает сохранить и в списке ничего нет, я хочу вызвать ошибку.Я решил использовать блок try catch следующим образом:
try
{
//when you go to save, and the list box is empty, you should get an error message
if (dataListBox.Items.Equals(null))
throw new Exception();
//i wanted to save on the form_close event, so i put the save data into a method and just call the method from this event
this.save();
}
catch (Exception err)
{
//spits out the errors if there are any
MessageBox.Show(err.Message, "List Box is empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Но это не работает для меня.Он все еще сохраняется, и окно сообщений не появляется.