我正在使用ComponentOne DataTree,它是一个带有子网格的FlexGrid。父网格有2列,一个是'Select'列,它是一个复选框,另一列是只读的。子网格有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"];
}
}
为什么网格不能获得行样式设置?
由于 格洛丽亚
答案 0 :(得分:1)
您无法像预期的那样使用OwnerDrawCell。在表单上加载FlexGrid后,使用以下代码段重新绘制只读列背景:
C1.Win.C1FlexGrid.CellStyle cs;
cs = _flex.Cols[2].StyleDisplay;
cs.BackColor = Color.White;
cs = _flex.Cols[3].StyleDisplay;
cs.BackColor = Color.White;
如果您需要更改子表的背景颜色,则必须单独更改每个子项的属性。使用以下代码段访问子表:
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;
}
}
}