Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGridRow.IsEditing从不返回true_C#_Wpf_Datagrid - Fatal编程技术网

C# DataGridRow.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

假设我的DataGrid中有5列5行。现在我想在编辑模式下获取currentRow的所有单元格。我成功地做到了。现在,我想禁用所有行,但单元格正在编辑的行除外。但在下面的代码中,r.IsEditing永远不会返回true。谁能解释一下为什么

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