Setting the row style of a ComponentOne DataTree FlexGrid

4.3k Views Asked by At

I am using a ComponentOne DataTree that is a FlexGrid with child grids. The parent grid has 2 columns a 'Select' column which is a checkbox and another column that is read-only. The child grid has 5 columns. The first is a checkbox and the other 4 are readonly. The read-only columns appear gray by default. I set the DataTable columns that is the data source of the grids to ReadOnly. I want the non-header columns to have a background of white by default. Neither grid is updated.

I define the style as a member variable and create the style in the Initialize method:

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

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

This is the OwnerDrawCell method that sets it:

 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"];                 
        }
    }

Why won't the grids get the row style setting?

Thanks Gloria

1

There are 1 best solutions below

0
On BEST ANSWER

You wont be able to use OwnerDrawCell as you've expected here. After the FlexGrid is loaded on the form use the following snippet used to repaint readonly columns background:

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

If you need to change the background color of the Child Tables you have to change each child's properties individually. Use the following snippet to access the Child tables:

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

To make the child tables in my C1FlexDataTree read-only:

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;
    }
}
}