在DevExpress中获取GridView的单元格控件

时间:2010-01-07 12:43:12

标签: c# gridview devexpress

我有一个GridView,它有一个RepositoryItemCheckEdit列作为ColumnEdit。我想只为一行禁用此控件。我怎样才能做到这一点?有什么建议吗?

3 个答案:

答案 0 :(得分:3)

我找到了解决问题的方法。

gridView1.CustomRowCellEditForEditing += OnCustomRowCellEditForEditing;

private void OnCustomRowCellEditForEditing(object sender, CustomRowCellEditEventArgs e)
{
    if (e.Column.FieldName != "MyFieldName") return;
        *code here*
        e.RepositoryItem.ReadOnly = true;
}

答案 1 :(得分:2)

您可以通过处理CustomRowCellEdit:

来使编辑器只读
private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
    if(code goes here)
        e.RepositoryItem.ReadOnly = true;
}

您还可以通过处理ShowingEditor来阻止编辑器显示:

private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
{
    if (code goes here)
        e.Cancel = true;
}

答案 2 :(得分:0)

继承DataGridViewColum重写方法InitializeEditingControl的类中的

它有参数rowIndex写这样的东西

this.DataGridView.EditingControl.Enbale = rowIndex != 3; // or the number you need