When the user clicks save, and there is nothing in the listbox, i want to raise an error. I figure I use a try catch block like so:
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);
}
But this isnt working for me, it still saves an no message box comes up.