c# - Object reference is not set -- WPF -- Rows Deletion -
i using wpf , devxpress. made 2 operations in application add , delete row grid. both working fine. if drag drop column deletion stops work delete multiple rows @ same time. here code , image, please answer query.
private void deletebutton_click(object sender, routedeventargs e) { if (dxmessagebox.show("are sure, want delete?", "delete item-confirmation", messageboxbutton.yesno, messageboximage.question) == messageboxresult.yes) { try { myentities dbcontext = new myentities(); name per = grid.selecteditem name; dbcontext.names.remove(per); dbcontext.savechanges(); refresh(); } } catch (exception ex) { dxmessagebox.show(ex.message.tostring()); }}}
where code below working fine delete single row:
name per = grid.selecteditem name; dbcontext.names.remove(per); dbcontext.savechanges();
you creating empty instance of dbcontext
, trying modify object within empty instance, non-existent.
make global instance (at class level) of myentities type, hold original instance objects. @ event, access global instance , modify objects in it.
Comments
Post a Comment