entity framework - why combBox.selectedItem can't be null? -


i have button named button2 should remove items table in database through entity framework.

i have combobox selects item should deleted. when don't select item exception happens selecteditem.tostring

object reference not set instance of object.

if use selectedvalue instead of selecteditem every time run program else branch executed if choose item

private void button2_click(object sender, eventargs e) {     firstentities db = new firstentities();      var st = db.students.tolist<student>()                .find(a => a.family == combobox1.selecteditem.tostring());      if (st != null)     {         db.students.remove(st);         db.savechanges();     }     else         messagebox.show("you didnt select student"); } 


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -