DEVEXPRESS GridControl 重绘分组行边框

在使用DEV控件库中的gridcontrol的分组功能时,需要给分组行加一个上边线,将不同的组明显的区隔开来,如下图。

重绘分组行,可实现该需求。此处只用了 AddRowLineInfo 这个方法画线,还有其他几个方法,有需要的话可以继续探索。

 1 private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
 2 {
 3     GridGroupRowInfo info = e.Info as GridGroupRowInfo;
 4     if (info == null) return;
 5     if (info.Column.FieldName == "CLASS")  //符合条件的分组行
 6     {
 7         GridGroupRowPainter painter = e.Painter as GridGroupRowPainter;
 8         Rectangle bounds = painter.GetGroupClientBounds(info);
 9         AppearanceObject appearance = new AppearanceObject();
10         appearance.BackColor = Color.Black;
11         info.AddRowLineInfo(bounds.X, bounds.Y-2, bounds.Width, 2, appearance);
12         e.Painter.DrawObject(info);
13     }
14 }

主要参考了以下几个链接:

https://www.devexpress.com/Support/Center/Question/Details/Q424679/gridview-customdrawgrouprow

https://www.cnblogs.com/wangfeng8317/p/4432151.html

https://blog.csdn.net/u011871201/article/details/70271798

猜你喜欢

转载自www.cnblogs.com/leticia1003/p/9729190.html