This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
MyAutoFilterRowHelper.cs
62 lines (56 loc) · 2.26 KB
/
MyAutoFilterRowHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.Utils.Drawing;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.Utils;
namespace WindowsApplication1
{
public class MyAutoFilterRowHelper
{
private readonly string _AutoFilterText;
private readonly GridView _View;
public MyAutoFilterRowHelper(GridView view, string text)
{
_View = view;
_AutoFilterText = text;
view.CustomDrawCell += view_CustomDrawCell;
// view.GridControl.Paint += GridControl_Paint;
view.GridControl.PaintEx += GridControl_PaintEx;
}
private void GridControl_PaintEx(object sender, PaintExEventArgs e)
{
if (!string.IsNullOrEmpty(_View.ActiveFilterString))
return;
Rectangle bounds = GetAutoFilterRowBounds();
if (e.ClipRectangle.IntersectsWith(bounds))
DrawAutoFilterRowText(_View, e.Cache, bounds);
}
public Rectangle GetAutoFilterRowBounds()
{
GridViewInfo viewInfo = _View.GetViewInfo() as GridViewInfo;
GridDataRowInfo rowInfo = viewInfo.GetGridRowInfo(GridControl.AutoFilterRowHandle) as GridDataRowInfo;
if (rowInfo == null || (rowInfo.RowState & GridRowCellState.Focused) != 0)
return Rectangle.Empty;
Rectangle r = rowInfo.DataBounds;
if (r.X < viewInfo.ViewRects.ColumnPanelLeft) r.X = viewInfo.ViewRects.ColumnPanelLeft;
if (r.Right > viewInfo.ViewRects.Rows.Right) r.Width = viewInfo.ViewRects.Rows.Right - r.X;
return r;
}
void view_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
if (e.RowHandle == GridControl.NewItemRowHandle)
e.Handled = true;
}
private void DrawAutoFilterRowText(GridView view, GraphicsCache cache, Rectangle r)
{
AppearanceObject appearance = view.PaintAppearance.TopNewRow;
appearance.DrawBackground(cache, r);
appearance.DrawString(cache, _AutoFilterText, r);
}
}
}