c# - Get selected record from datagrid wpf? -
i've got table in picture. according post field checkbox , if checked write file , delete records database. if not checked records remain in database.problem when try access records exception(cant find onject) because trying access datagrid.selectedindex giving me datagrid index , not record index. there way of getting record index? ve got automatic index incremented 1 unique id each record.

thanks in advance
if use viewmodel or can use command , selected datagridrow commandparameter. in command can access underlining data , check "post" property , wirte file , delete row collection.
<buttons command="{binding writecommand}" commandparameter="{binding elementname=mydatagridctrl, path=selecteditem}" /> if have datatable datasource command following
private delegatecommand<datarowview> _writecommand ; public icommand writecommand { { return this._writecommand ?? (this._writecommand = new delegatecommand<datarowview>(this.writecommandexecute, this.canwritecommandexecute)); } } private bool caneditdatacommandexecute(datarowview rowtowrite) { return rowtowrite!= null && (bool)rowtowrite["post"];//if post bool } private void editdatacommandexecute(datarowview rowtowrite) { if (!this.caneditdatacommandexecute(rowtowrite)) return; //do stuff here }
Comments
Post a Comment