Problems catching an exception in c# -
i have combobox 2 items. have button opens new form when 1 of these items selected. if none of items selected there exception(nullpointer). have tried (to no avail) grab exception , show mbox prompts user take 1 of items.
here code button click even:
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(); } }
you not supposed utilize exceptions flow command in non-exceptional cases. case user didn't select certainly not exceptional.
the right approach simple null
check:
if(cbtable.selecteditem == null) { // show message box } else { // current code }
why exception handling code isn't working impossible answer, because didn't include in question.
c# exception combobox buttonclick
No comments:
Post a Comment