In WPF, click the DataGrid, how do I get the row currently clicked?
For example, in the MouseDoubleClick event, in fact the selected row is a DataRowView, you can use the following methods to get the data of the selected row, you need to refer to system. IO and System.Data;
var a =this.exdatagrid.selectitem;
var b= a as DataRowView;
or Var b= (DataRowView) Exdatagrid.selectitem
b["Filedname"]. ToString (); Where the data you can convert directly
Note, however, that if the ItemsSource of your DataGrid is a collection of objects rather than a DataTable, then using Datagrid.selecteditem as Youclass can be obtained. For example, in LINQ to SQL your Itemsource is a collection of objects, which is treated as a class object, except that you should convert the type of the table (the product table corresponds to the product class in DBML)
var myselectedelement = (Product) Exdatagrid.selecteditem;
int Selectedid=myselectedelement.productid;
WPF DataGrid Gets the data for the selected row