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());              }}} 

enter image description here

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

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -