我有一个可编辑的数据网格,其中有几个月的列和几行,它们根据搜索条件而变化。可以在这些单元格中输入数字,这些数字的总和添加到最后一行,并由我在 CellEditEnding 中计算事件。但是 Total 的最后一行也是可编辑的,这是不允许的,有没有办法使最后一行只读。
有使 DataGrid 只读和列只读的属性,但没有仅使特定行只读的属性。
我在帖子中尝试了以下代码
private void dataGrid_LoadingRow_1(object sender, DataGridRowEventArgs e)
{
if (e.Row.IsNewItem)
e.Row.IsEnabled = true;
else
e.Row.IsEnabled =false;
}
但这行不通。
我尝试获取数据网格行
DataGridRow lastRow = this.dataGrid.Items[rowCount - 1];
lastRow.IsReadOnly = true;
但是 DataGridRow 没有任何 IsReadOnly 属性
找到解决方案,必须使用BeginningEdit事件
private void WdgModelwiseForecast_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
if (e.Row.Item == wdgModelwiseForecast.Items[wdgModelwiseForecast.Items.Count - 1])
{
// Cancel the edit operation for the last row
e.Cancel = true;
}
}