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