使网格中的单元格不可编辑

时间:2012-05-17 16:44:04

标签: c# winforms syncfusion

在我的syncfusion网格中,我必须根据类型使一些系列单元格不可编辑。 如果类型是'XXX',那么单元格是可编辑的, 如果类型是'YYY','ZZZ'则单元格是不可编辑的

所以这里;我做的。

 private void theGrid_CurrentCellChanging(object sender, System.ComponentModel.CancelEventArgs e)
    {
        fp_data_typ typ;
        int nSeries = theData.GetNumSeries();
        for (int i = 0; i < nSeries; i++)
        {
            typ = theData.CheckType(i);
            if (!(typ == 'XXX'))
            {

                e.Cancel = true;
            }
        }

    }

我不确定是否应该使用theGrid_CurrentCellChanging事件或者Grid_CurrentCellEartEditing。文档不是很清楚。给了我很多事件来处理单元格编辑。

之前的代码工作方式不正确。如果网格具有可编辑和不可编辑系列的组合,则它不起作用。我:如果它同时具有xxx)可编辑和'yyy'(不可编辑),则它都是不可编辑的。

2 个答案:

答案 0 :(得分:0)

我能够获取当前单元格的列索引,并从那里将e.cancel设置为true / false。我没有为整个网格设置一次e.cancel,而是去了正在编辑的单元格。

答案 1 :(得分:0)

以下活动将帮助您实现您的要求。

//Use this if you want to control the ReadOnly setting while loading itself
grid.QueryCellInfo += new GridQueryCellInfoEventHandler(grid_QueryCellInfo);

void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    if (e.Style.CellValue.Equals("YYY"))
    {
        e.Style.ReadOnly = true;
    }
}

//Use this if you want to Validate while Editing
grid.CurrentCellValidating += new CurrentCellValidatingEventHandler(grid_CurrentCellValidating);

void grid_CurrentCellValidating(object sender, CurrentCellValidatingEventArgs e)
{
    //Will deactive the cell and new value will be discarded
    //e.NewValue = e.OldValue;

    //To remain in Edit mode without committing the vlaue
    e.Cancel = true;
}

谢谢, 西瓦库玛