C# DataGridRow.IsEditing从不返回true
假设我的DataGrid中有5列5行。现在我想在编辑模式下获取currentRow的所有单元格。我成功地做到了。现在,我想禁用所有行,但单元格正在编辑的行除外。但在下面的代码中,r.IsEditing永远不会返回true。谁能解释一下为什么C# DataGridRow.IsEditing从不返回true,c#,wpf,datagrid,C#,Wpf,Datagrid,假设我的DataGrid中有5列5行。现在我想在编辑模式下获取currentRow的所有单元格。我成功地做到了。现在,我想禁用所有行,但单元格正在编辑的行除外。但在下面的代码中,r.IsEditing永远不会返回true。谁能解释一下为什么 for (int column = 0; column <= dg.Columns.Count - 1; column++) { if (!(GetDataGridCell(new DataGridCellInfo(dg.Items[rowIn
for (int column = 0; column <= dg.Columns.Count - 1; column++)
{
if (!(GetDataGridCell(new DataGridCellInfo(dg.Items[rowIndex], dg.Columns[column])).IsReadOnly))
{
GetDataGridCell(new DataGridCellInfo(dg.Items[rowIndex], dg.Columns[column])).IsEditing = true;
}
}
foreach (DataGridRow r in rows)
{
if (!(r.IsEditing))
{
r.IsEnabled = false;
}
}
这有点棘手。我需要在代码中添加以下行以使其正常工作:
dg.CurrentCell = new DataGridCellInfo(dg.Items[rowIndex], dg.Columns[0]);
dg.BeginEdit();
现在,我的完整代码如下所示:
dg.CurrentCell = new DataGridCellInfo(dg.Items[rowIndex], dg.Columns[0]);
dg.BeginEdit();
for (int column = 0; column <= dg.Columns.Count - 1; column++)
{
if (!(GetDataGridCell(new DataGridCellInfo(dg.Items[rowIndex], dg.Columns[column])).IsReadOnly))
{
GetDataGridCell(new DataGridCellInfo(dg.Items[rowIndex], dg.Columns[column])).IsEditing = true;
}
}
foreach (DataGridRow r in rows)
{
if (!(r.IsEditing))
{
r.IsEnabled = false;
}
}