【WinForm+DevExpress】GridView为表头添加筛选功能
效果图实现:第一步:新建一个DevExpress Form,加入一个GridControl,设置父容器停靠第二步:创建测试数据,并且设置GridView数据源public XtraGridCustomDrawSortFilterButtonsDemo(){InitializeComponent();Li...
·
效果图
实现:
第一步:新建一个DevExpress Form,加入一个GridControl,设置父容器停靠
第二步:创建测试数据,并且设置GridView数据源
public XtraGridCustomDrawSortFilterButtonsDemo()
{
InitializeComponent();
List<Cars> CarList = new List<Cars>();
Cars data1 = new Cars();
data1.Make = "Audi";
data1.Model = "A6";
data1.Automatic = true;
CarList.Add(data1);
Cars data2 = new Cars();
data2.Make = "Audi";
data2.Model = "RS4";
data2.Automatic = false;
CarList.Add(data2);
Cars data3 = new Cars();
data3.Make = "Benz";
data3.Model = "G63";
data3.Automatic = true;
CarList.Add(data3);
gridControl1.DataSource = CarList;
}
第三步:设置GridView的CustomDrawColumnHeader事件
private void gridView1_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column == null) return;
Rectangle rect = e.Bounds;
ControlPaint.DrawBorder3D(e.Graphics, e.Bounds);
Brush brush = e.Cache.GetGradientBrush(rect, Color.White, Color.LightCyan,
e.Column.AppearanceHeader.GradientMode);
rect.Inflate(-1, -1);
e.Graphics.FillRectangle(brush, rect);
e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
//为表头的每一列添加筛选按钮
foreach (DrawElementInfo info in e.Info.InnerElements)
{
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
}
e.Handled = true;
}
更多推荐
已为社区贡献3条内容
所有评论(0)