【问题标题】:Devexpress Gridview - Allow certain rows to be editable, not allDevexpress Gridview - 允许某些行可编辑,而不是全部
【发布时间】:2020-03-30 05:52:40
【问题描述】:

我有一个可以从 XML 文件加载记录的 gridview。现在,当此列表加载到 gridview 中时,其中可能有一些记录有一个子对象,例如 Component,插入为 new(我们的数据库中已经不存在)。

有条件地,如果我们有一个 从列表中,我们将允许用户编辑子对象的某些字段,例如Carrier & Info

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

【问题讨论】:

    标签: c# devexpress devexpress-gridcontrol


    【解决方案1】:

    我建议你通过下面的 DevExpress 线程:

    How to Conditionally Prevent Editing for Individual Grid Cells

    根据条件使网格单元格只读的最佳方法是处理GridView.ShowingEditor 事件并在需要阻止编辑时将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;  
    }
    

    参考资料:
    XtraGrid conditional edit

    【讨论】:

      【解决方案2】:

      我尝试处理 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;
                }
      
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-16
        • 1970-01-01
        相关资源
        最近更新 更多