【问题标题】:Setting the row style of a ComponentOne DataTree FlexGrid设置 ComponentOne DataTree FlexGrid 的行样式
【发布时间】:2014-08-06 19:06:04
【问题描述】:

我正在使用一个 ComponentOne DataTree,它是一个带有子网格的 FlexGrid。父网格有 2 列,“选择”列是一个复选框,另一列是只读的。子网格有 5 列。第一个是复选框,其他 4 个是只读的。默认情况下,只读列显示为灰色。我将作为网格数据源的 DataTable 列设置为 ReadOnly。我希望非标题列默认具有白色背景。两个网格都没有更新。

我将样式定义为成员变量,并在 Initialize 方法中创建样式:

C1.Win.C1FlexGrid.CellStyle defaultRowStyle;
 private void InitializeControls()
    {
        txtWorkZone.Enabled = true;
        txtWorkZone.Focus();

        defaultRowStyle = c1flxdatatreeCasePick.Styles.Add("DefaultRowStyle");
        defaultRowStyle.BackColor = Color.White;
    }

这是设置它的 OwnerDrawCell 方法:

 private void c1flxdatatreeCasePick_OwnerDrawCell(object sender, OwnerDrawCellEventArgs e)
    {
        C1FlexDataTree grid = sender as C1FlexDataTree;
        if (grid == null || grid.DataSource == null)
            return;

        if(e.Row > 0)
            grid.Rows[e.Row].Style = grid.Styles["DefaultRowStyle"];

        //Get the child grid
        C1FlexDataTree childGrid = grid.Rows[e.Row].UserData as C1FlexDataTree;

        if (childGrid != null)
        {
            if(e.Row > 0)
                 childGrid.Rows[e.Row].Style = grid.Styles["DefaultRowStyle"];                 
        }
    }

为什么网格不会获得行样式设置?

谢谢 格洛丽亚

【问题讨论】:

    标签: c# styles componentone c1flexgrid


    【解决方案1】:

    您将无法像预期的那样使用 OwnerDrawCell。在表单上加载 FlexGrid 后,使用以下 sn-p 重新绘制只读列背景:

    C1.Win.C1FlexGrid.CellStyle cs;
    cs = _flex.Cols[2].StyleDisplay;
    cs.BackColor = Color.White;
    cs = _flex.Cols[3].StyleDisplay;
    cs.BackColor = Color.White;
    

    如果您需要更改子表的背景颜色,您必须单独更改每个子表的属性。使用以下 sn-p 访问子表:

    for (int row = 0; row <  _flex.Rows.Count; row++)
    {
    C1FlexDataTree child = _flex.Rows[row].UserData as C1FlexDataTree;
    if (child != null)
    {
          // Access Child Tables here 
    }
    }
    

    使我的 C1FlexDataTree 中的子表为只读:

    for (int row = 0; row <  _flex.Rows.Count; row++)
    {
    C1FlexDataTree child = _flex.Rows[row].UserData as C1FlexDataTree;
    if (child != null)
    {
        foreach (Column c in child.Cols)
        {
            c.AllowEditing = false;
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      相关资源
      最近更新 更多