C# Datagrid列IsReadOnly属性在Silverlight 4中不工作?
我目前正在使用DataGrid,在某些情况下,它应该通过将C# Datagrid列IsReadOnly属性在Silverlight 4中不工作?,c#,silverlight-4.0,datagrid,C#,Silverlight 4.0,Datagrid,我目前正在使用DataGrid,在某些情况下,它应该通过将IsReadOnly更改为true来禁用或启用特定列,反之亦然。 我附加到CurrentCellChanged和CellEditEnded事件,在这些事件中我更改了列IsReadOnly属性。 我希望应用程序禁用/启用对该列的编辑。 即使列的IsReadOnly设置为true,有时也允许编辑。 我还尝试调用CancelEdit()在网格上,但这也没有产生任何效果。 如果您要求,我可以发布代码,但我非常确定逻辑是好的,我在debug;)中检
IsReadOnly
更改为true来禁用或启用特定列,反之亦然。
我附加到CurrentCellChanged
和CellEditEnded
事件,在这些事件中我更改了列IsReadOnly
属性。
我希望应用程序禁用/启用对该列的编辑。
即使列的IsReadOnly
设置为true,有时也允许编辑。
我还尝试调用CancelEdit()代码>在网格上,但这也没有产生任何效果。
如果您要求,我可以发布代码,但我非常确定逻辑是好的,我在debug;)中检查了数千次。
整个想法只不过是在事件中改变某个专栏。
你知道为什么它不能像我期望的那样工作吗
Edit1.
代码添加
private void SrfDataGrid_CurrentCellChanged(object sender, EventArgs e)
{
CellCoordinates cellCoordinates = this.GetEditedCellCoordinates();
if (!this.LockDataGridCell(cellCoordinates))
{
if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && !Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
this.srfDataGrid.BeginEdit();
}
else
{
this.srfDataGrid.CancelEdit();
}
}
private void SrfDataGrid_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e)
{
CellCoordinates cellCoordinates = this.GetEditedCellCoordinates();
this.SetCellsRowInfluence(cellCoordinates);
this.UnlockDataGridCell(cellCoordinates);
}
public bool LockDataGridCell(CellCoordinates cellCoordinates)
{
bool result = false;
if (cellCoordinates != null)
{
DataGridColumn currentColumn = this.srfDataGrid.CurrentColumn;
if (this.spreadSheetCellState[cellCoordinates.ColumnName, cellCoordinates.RowID].Equals(CurrentCellState.WRITE))
{
currentColumn.IsReadOnly = false;
}
else
{
currentColumn.IsReadOnly = true;
}
result = currentColumn.IsReadOnly;
}
return result;
}
public void UnlockDataGridCell(CellCoordinates cellCoordinates)
{
if (cellCoordinates != null)
{
DataGridColumn currentColumn = this.srfDataGrid.CurrentColumn;
if (this.spreadSheetCellState[cellCoordinates.ColumnName, cellCoordinates.RowID].Equals(CurrentCellState.ALWAYS_READ_ONLY))
{
currentColumn.IsReadOnly = true;
}
else
{
currentColumn.IsReadOnly = false;
}
}
}
试试这个:
foreach (DataGridColumn col in dataGrid1.Columns)
{
if (col.GetType() == typeof(DataGridTextColumn))
{
col.IsReadOnly = true;
}
else
{
col.IsReadOnly = false;
}
}
请附上代码,我们讨厌文字!好的,我附上了最重要的代码