我使用的是一个带有子网格的FlexGrid的ComponentOne DataTree。父网格有2列,"选择"列是一个复选框,另一列是只读的。子网格有5列。第一个是一个复选框,另外4个是只读的。只读列默认显示为灰色。我将作为网格数据源的DataTable列设置为只读。我希望非标题列在默认情况下有白色的背景。两个网格都没有更新。
我将样式定义为成员变量,并在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"];
}
}
为什么网格不能得到行样式设置?
谢谢格洛丽亚
你不能像你期望的那样使用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;
}
}
}