2013-04-27 153 views
0

我有一个Devexpress Xtragrid,其中我根据特定的列对行进行分组。我给组添加了深蓝色背景颜色,并将ShowGroupExpandCollpaseButton也设置为false。在网格中每个子行的最左侧显示我设置为组背面颜色的颜色。有没有什么办法去除这种颜色。请指导我。行背景颜色行组问题

enter image description here

+1

这是集团列对? – Bit 2013-04-27 10:49:30

+0

是的,是否有任何限制来隐藏它? – 17CrazyBrain 2013-04-28 05:34:33

回答

1

为了完成这个任务,请从GroupRow外观删除BackColor。 然后使用CustomDrawGroupRow事件凸显组一行内容,因为你需要:

// 1) remove GroupRow style 
    //gridView1.Appearance.GroupRow.BackColor = Color.Blue; 

    gridView1.OptionsView.ShowGroupExpandCollapseButtons = false; 

    // 2) use the CusomDrawGroupRow 
    gridView1.CustomDrawGroupRow += gridView1_CustomDrawGroupRow; 
} 

void gridView1_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e) { 
    GridView gridView = sender as GridView; 
    GridGroupRowInfo groupRowInfo = e.Info as GridGroupRowInfo; 
    string groupRowText = gridView.GetGroupRowDisplayText(e.RowHandle); 
    int textStart = groupRowInfo.DataBounds.Left + 4; 
    Rectangle groupRowTextBounds = new Rectangle(
      textStart, 
      groupRowInfo.Bounds.Top, 
      groupRowInfo.Bounds.Right - textStart, 
      groupRowInfo.Bounds.Height 
     ); 
    e.Cache.FillRectangle(Brushes.Blue, e.Bounds); // draw blue backgrownd 
    e.Appearance.DrawString(e.Cache, groupRowText, groupRowTextBounds); 
    e.Handled = true; 
} 
+0

谢谢你的解决方案。这是工作。现在,如果我们分组,网格在每个子行的开始处留下一些额外的空间。有什么办法可以消除这个?你能提出一些解决方案吗? – 17CrazyBrain 2013-04-29 05:03:47

+0

@ 17CrazyBrain指定[级别缩进](http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsGridGridView_LevelIndenttopic)如下:'gridView1.LevelIndent = 0;' – DmitryG 2013-04-29 06:55:05

+0

这是完美的。多谢... – 17CrazyBrain 2013-04-30 10:59:19

0

您应该能够通过设置来隐藏视图中的组,如下所示:

this.gridView1.OptionsView.ShowGroupedColumns = false; 
+0

谢谢你的解决方案。但是,这样它就无法工作。 – 17CrazyBrain 2013-04-29 04:58:06