c# - Returning/Getting DataGrid Row index from button click -
i'm having trouble returning row button clicked in wpf project.
i have following far...
xaml -
<datagrid x:name="mydatagrid" horizontalalignment="left" width="550"> <datagrid.columns> <datagridtextcolumn header="name"></datagridtextcolumn> <datagridtemplatecolumn width="200"> <datagridtemplatecolumn.celltemplate> <datatemplate> <button click="rowevent">x</button> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> </datagrid.columns> </datagrid>
c# -
private void rowevent(object sender, routedeventargs e) { button btn = sender button; }
i seem recall when using datagridview in win forms row index e.rowindex if remember correctly, cant seem time.
could point me in right direction?
just use:
datagrid.selectedindex property
... this:
private void rowevent(object sender, routedeventargs e) { int index = mydatagrid.selectedindex; messagebox.show(index.tostring()); }
Comments
Post a Comment