草庐IT

DataGridCell

全部标签

c# - 从 DataGrid 中选择 DataGridCell

我有一个DataGridWPF控件,我想获得一个特定的DataGridCell。我知道行和列索引。我该怎么做?我需要DataGridCell因为我必须能够访问它的内容。因此,如果我有(例如)一列DataGridTextColum,我的内容将是一个TextBlock对象。 最佳答案 您可以使用与此类似的代码来选择一个单元格:vardataGridCellInfo=newDataGridCellInfo(dataGrid.Items[rowNo],dataGrid.Columns[colNo]);dataGrid.SelectedCel

c# - WPF 数据网格 : How to Determine the Current Row Index?

我正在尝试基于DataGrid实现一个非常简单的电子表格功能。用户点击一个单元格用户键入一个值并按回车键扫描当前行并更新依赖于所单击单元格的任何单元格公式。这似乎是满足我要求的最佳事件处理程序:privatevoidmy_dataGrid_CurrentCellChanged(objectsender,EventArgse)问题:如何检测当前行的行索引? 最佳答案 试试这个(假设您的网格名称是“my_dataGrid”):varcurrentRowIndex=my_dataGrid.Items.IndexOf(my_dataGrid