Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.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# Devexpress Gridview-允许某些行可编辑,而不是所有行_C#_Devexpress_Devexpress Gridcontrol - Fatal编程技术网

C# Devexpress Gridview-允许某些行可编辑,而不是所有行

C# Devexpress Gridview-允许某些行可编辑,而不是所有行,c#,devexpress,devexpress-gridcontrol,C#,Devexpress,Devexpress Gridcontrol,我有一个gridview,可以从XML文件加载记录。现在,当这个列表被加载到gridview中时,其中可能有一些记录有一个子对象,比如说组件作为新的插入(在我们的数据库中还不存在) 有条件地,在此gridview中,不允许用户更改子对象组件的任何字段,但是如果我们从列表中新建了子对象,我们将允许用户编辑子对象的某些字段,例如Carrier和Info 我的问题是如何允许编辑器仅显示在网格中的某些行,在这种情况下,子对象为Component.Inserted=true的行我尝试处理gridview的

我有一个gridview,可以从XML文件加载记录。现在,当这个列表被加载到gridview中时,其中可能有一些记录有一个子对象,比如说
组件
作为
新的
插入(在我们的数据库中还不存在)

有条件地,在此gridview中,不允许用户更改子对象
组件的任何
字段
,但是如果我们从列表中新建了子对象,我们将允许用户编辑子对象的某些字段,例如
Carrier
Info


我的问题是如何允许编辑器仅显示在网格中的某些行,在这种情况下,子对象为
Component.Inserted=true的行

我尝试处理gridview的
ShowingEditor
事件,如下所示:

private void gridViewRecords_ShowingEditor(object sender, CancelEventArgs e)
{
    //gets focused row and casts it into my object
    MyObject mo = (MyObject) gridViewRecords.GetRow(gridViewRecords.FocusedRowHandle);

    //check for my condition
    if(!(mo.Component.Inserted))
    {

          //intended cols, whose editor I want to block
          if(gridViewRecords.FocusedColumnName == "colCarrier"){
               e.Cancel = true;
          }
          else
          if(gridViewRecords.FocusedColumnName == "colInfo"){
               e.Cancel = true;
          }

    }
}

我建议您使用以下DevExpress线程:

根据条件使网格单元格只读的最佳方法是处理事件,并在需要防止编辑时将e.Cancel参数设置为true

例如:

// disable editing  
private void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) {  
    GridView view = sender as GridView;  
    if(view.FocusedColumn.FieldName == "Region" && !USCanada(view, view.FocusedRowHandle))  
        e.Cancel = true;  
}
参考文献: