Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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# Datagrid列IsReadOnly属性在Silverlight 4中不工作?_C#_Silverlight 4.0_Datagrid - Fatal编程技术网

C# Datagrid列IsReadOnly属性在Silverlight 4中不工作?

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;)中检

我目前正在使用DataGrid,在某些情况下,它应该通过将
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;
            }
        }

请附上代码,我们讨厌文字!好的,我附上了最重要的代码