c# - How to identify only change rows in datagrid which is bind ObservableCollection in WPF MVVM -
i have data grid bind observable collection. first load data database. if change 1 row , click on save button should update particular row. if add new rows, when click save id should insert rows database. don't have doubt update , insert database. problem how identify row changes.
<datagrid selectedindex="{binding selectedintex}" isenabled="{binding iskeyset}" canuserdeleterows="false" canuseraddrows="false" name="dgwtemplatedetails" selectionmode="single" itemssource="{binding ordertemplatelist, mode=twoway}" selecteditem="{binding selectedordertemplate}" isreadonly="false" autogeneratecolumns="false" width="auto"> <datagrid.columns> <datagridtextcolumn header="change state" visibility="visible" binding="{binding changestate}"/> <datagridtextcolumn header="srl no" visibility="hidden" binding="{binding srlno}"/> <datagridtextcolumn header="act code" width="75" binding="{binding actcode}"/> <datagridtextcolumn header="act name" width="275" binding="{binding actname}"/> <datagridtextcolumn header="no. of days" width="75" binding="{binding noofdays}"/> <datagridcheckboxcolumn header="is cutting" width="75" binding="{binding iscutselected}" /> </datagrid.columns> </datagrid>
as far aware, there no way identify this. can add property in class called haschanged
public bool haschanged { get; set; }
and in setter code of of other properties, set haschanged property true. example:
private string _actname; public string actname { { return _actname; } set { _actname = value; this.haschanged = true; //inotifypropertychanged stuff if using here. } }
when save changes database, can select of records has changed property set true.
var haschanged = ordertemplatelist.where(x => x.haschanged);
Comments
Post a Comment