【发布时间】:2018-05-07 18:32:55
【问题描述】:
我找到的都是关于 DataGridView 的,并且已经尝试了一些事件处理程序,但我现在卡住了。
假设我有如下的 DataGrid:
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Code", typeof(String));
dt.Columns.Add("Name", typeof(String));
gridData.DataSource = dt;
我如何使用SelectedRows["ID"] 捕获onClick 事件
这个solution 适用于DataGridView,但不适用于DataGrid。
【问题讨论】:
-
您使用的是哪个 .NET 版本?
-
@CryogenicNeo:.NET Framework 4.6.1
-
SelectedCells属性在此版本的 .NET 中可用,它必须是可能的。 -
@CryogenicNeo:遗憾的是不适用于 Windows 窗体。是的 WPF。
-
来自MSDN on the DataGrid control "DataGridView 控件替换了 DataGrid 控件并向其添加了功能;但是,如果您愿意,可以保留 DataGrid 控件以供向后兼容和将来使用。"我认为您最好的选择是改用 DataGridView。