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);
}
}

猜你喜欢

转载自blog.csdn.net/cjx120105102/article/details/52986363
今日推荐