DevExpress GridView 列标题的颜色是跟随皮肤的,直接修改BackColor是无效的,除非去掉皮肤,若不想去皮肤或者修改皮肤的话,可以采用gridview的CustomDrawColumnHeader事件去处理,
注册这个事件,颜色设置直接设置GridColumn的backColor即可。
注册事件:
gridview.CustomDrawColumnHeader+=OnCustomDrawColumnHeader
-
private void OnCustomDrawColumnHeader(object sender,ColumnHeaderCustomDrawEventArgs e)
-
{
-
//背景颜色没有设置且为空,则默认
-
if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor))
-
return;
-
Rectangle rect = e.Bounds;
-
rect.Inflate(-1, -1);
-
// 填充标题颜色.
-
e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect);
-
e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
-
// 绘制过滤和排序按钮.
-
foreach (DrawElementInfo info in e.Info.InnerElements)
-
{
-
if (!info.Visible) continue;
-
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
-
}
-
e.Handled = true;
-
}
在设计器设置列的AppearanceHeader 的相关属性即可
效果图: