c# - Discard changes made in a Gridcontrol when a user clicks the "Cancel" button and exit -


i have 2 forms. first forms creating/updating person , has button 2nd form holds information person's children using devexpress gridcontrol.

i let user option crud children form when created new person (maybe design failure me that's matter). when finish filling children details can hit "save" or "cancel , exit" buttons. if hit "cancel.." need underlying children datatable revert way before. tried canceledit() method of bindingsource without success. tried next thing:

void cancelbtn_click(object sender,eventargs e)  {          datatable dt = (datatable)bindingsource.datasouce datatable;          dt.rejectchanges(); } 

which doesn't work if first time open , crud children grid , hit save , on second time open other stuff , hit cancel revert first save operations cause update database when user finish creating person , hit "save" on person form , not in between children form updates.

i'm taking care of relation manually have have person row , id created first , save children database.

am doing wrong ?

you need use datatable variable hold values second form , use variable gridcontrol.datasource instead of bindingsource. when user clicks save button need update details table.

here example:

0. create datatable second form:

var secondformtable = new datatable();  foreach (datacolumn column in detailstable.columns)     secondformtable.columns.add(column.columnname, column.datatype);  secondformtable.columns.add("detailsrow", typeof(datarow));  foreach (var detailsrow in detailstable.select("some filter child rows")) {     var secondformrow = secondformtable.rows.add(detailsrow.itemarray);     secondformrow["detailsrow"] = detailsrow; }  secondformtable.acceptchanges();  secondformgridcontrol.datasource = secondformtable; 

and when user clicks save button need update details table.

1. update details table secondformtable:

void savebtn_click(object sender, eventargs e)  {     var secondformtable = (datatable)secondformgridcontrol.datasouce;      foreach (datarow secondformrow in secondformtable.rows)         switch (secondformrow.rowstate)         {             case datarowstate.added:             case datarowstate.modified:                 datarow detailsrow;                  if (secondformrow.rowstate == datarowstate.added)                 {                     detailsrow = detailstable.newrow();                     detailstable.rows.add(detailsrow);                 }                 else                     detailsrow = (datarow)secondformrow["detailsrow"];                  foreach (datacolumn column in detailstable.columns)                     detailsrow[column] = secondformrow[column.columnname];                 break;              case datarowstate.deleted:                 ((datarow)secondformrow["detailsrow", datarowversion.original]).delete();                 break;         } } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -