1

我正在使用 Sourcegrid.DataGrid,其选择模式设置为

this.dataGrid1.SelectionMode = SourceGrid.GridSelectionMode.Row;

我需要禁用编辑(双击)单个单元格。

我知道如何使用禁用整个列

this.dataGrid1.Columns[0].DataCell.Editor.EnableEdit = false;

但我不知道如何禁用单个单元格。

有人可以解释一下该怎么做吗?

4

1 回答 1

1

感谢 Marek 的努力,但您的解决方案是另一个 .net 控件。

我找到了解决问题的方法。我认为控件上存在避免禁用单个单元格的错误(或者我还没有找到正确的解决方案来执行此操作)。

如果我有一个带有固定/预定义文本的单元格,我可以使用以下代码阻止编辑

private void dataGrid1_DoubleClick(object sender, EventArgs e)
{
    SourceGrid.DataGrid dg = (SourceGrid.DataGrid)sender;
    //Get the position of the clicked cell
    int c = dg.MouseCellPosition.Column;
    int r = dg.MouseCellPosition.Row;
    //create a Cell context 
    SourceGrid.CellContext cc = new SourceGrid.CellContext(dg, new SourceGrid.Position(r,c));
    //and retrieve the value to be compared with a pre-defined text
    if (String.Compare(cc.DisplayText, "SOMETEXT") == 0)
        this.dataGrid1.GetCell(r, c).Editor.EnableEdit = false; //Disable the editing 
    else
        this.dataGrid1.GetCell(r, c).Editor.EnableEdit = true;  //Enable the editing
}

我希望这可以帮助某人。

问候,
亚历克斯

于 2013-07-19T13:55:01.763 回答