1. 程式人生 > >DataGrid選中任意一行,獲取其中的資訊

DataGrid選中任意一行,獲取其中的資訊

DataGrid選中任意一行,獲取其中的資訊

 在網上查了好多資源都得不到想要的結果,甚至還有說,DataGrid是不能精確的選中行和列的。看了好長時間,終於搞出來了,在這裡和大家分享下,希望可以給你提供幫助。

//在DataGrid上觸發SelectedCellsChanged事件
private void dataGrid_SelectedCellsChanged(object sender,SelectCellsChangedEventArgs e)
{
DataRowView dt = (dataGrid.CurrentItem as DataRowView);
if( dt != null)
{
string id = (dt.Row[0] as string);
}
}