我使用的是一个ComponentOne DataTree,它是一个带有子网格的FlexGrid。父网格有两个列,一个是“选择”列,它是一个复选框,另一个列是只读的。子网格有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"];
}
}为什么网格不能得到行样式的设置?
谢谢格洛丽亚
发布于 2014-08-12 05:17:20
您将无法像您在这里所期望的那样使用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;
}
}
}https://stackoverflow.com/questions/25168244
复制相似问题