Back to Devexpress

ColumnView.CustomDrawFilterPanel Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-7c0ecb31.md

latest11.6 KB
Original Source

ColumnView.CustomDrawFilterPanel Event

Enables you to paint the filter panel manually.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("CustomDraw")]
public event CustomDrawObjectEventHandler CustomDrawFilterPanel
vb
<DXCategory("CustomDraw")>
Public Event CustomDrawFilterPanel As CustomDrawObjectEventHandler

Event Data

The CustomDrawFilterPanel event's data class is CustomDrawObjectEventArgs. The following properties provide information specific to this event:

PropertyDescription
AppearanceGets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
BoundsReturns a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
CacheProvides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX hardware acceleration to learn more. Inherited from CustomDrawEventArgs.
GraphicsA GDI+ drawing surface. Use the CustomDrawEventArgs.Cache property instead if you enable the DirectX hardware acceleration. Inherited from CustomDrawEventArgs.
HandledGets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs.
InfoGets an object containing information about the painted element.
PainterGets the painter object that provides the default element painting mechanism.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Performs default painting of an element. Inherited from CustomDrawEventArgs.
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from CustomDrawEventArgs.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. Inherited from CustomDrawEventArgs.

Remarks

The appearance of the filter panel can be customized via the ColumnViewAppearances.FilterPanel object. Handle the CustomDrawFilterPanel event to get complete control over the panel’s painting. See the Custom Painting Basics and Custom Painting Scenarios topics for information on using custom draw events.

The CustomDrawFilterPanel event is raised before the filter panel is repainted. Handle this event to paint the panel manually or to paint additional elements on it. Information about the filter panel and its inner elements can be obtained via the CustomDrawObjectEventArgs.Info parameter. To obtain the text for the filter conditions applied, use the View’s FilterPanelText property. Refer to the Filter and Search topic for more information.

The event’s CustomDrawObjectEventArgs.Info is an instance of DevExpress.XtraGrid.Drawing.GridFilterPanelInfoArgs. Its properties contain information on the inner elements of the filter panel:

|

Property

|

Description

| | --- | --- | |

Info.ActiveButtonInfo

|

Contains information (bounds and check state) on the Enable Filter check box.

| |

Info.CloseButtonInfo

|

Contains information on the filter panel Close Button.

The Button property of the EditorButton class can be used to change the appearance of the Close button. For instance, to display a custom image within the button, set the Button.Kind property to ButtonPredefines.Glyph and assign an image to display to the Button.Image property.

The Appearance object allows you to change the Close button’s appearance settings. Note that these settings are in effect only if the View is not painted using a WindowsXP theme or Office2003 scheme.

| |

Info.DisplayText

|

Can be used to get and set the text displayed within the filter panel. Initially this property matches the value of the FilterPanelText property.

| |

Info.FilterActive

|

Specifies whether the filtering functionality is enabled. Manually changing this property will affect how the Activate Filter check box is painted (checked or unchecked).

| |

Info.MRUButtonInfo

|

Contains information on the filter panel’s button which opens the list containing the most recently used filter criteria. This button can be customized in the same manner as the Close button.

|

If the panel has been custom painted, set the CustomDrawEventArgs.Handled parameter to true to prevent the default painting.

Important

Do not change cell values, modify the control’s layout, or change the control’s object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

Example

The following code demonstrates how to manually repaint the filter panel.

csharp
using DevExpress.XtraGrid.Drawing;

private void Form3_Load1(object sender, EventArgs e) {
    CustomDrawFilterPanel(gridControl1, gridView1);
}

public static void CustomDrawFilterPanel(GridControl gridControl, GridView gridView) {
    gridView.ActiveFilterString = string.Format("[{0}] > 2", "ID");

    // Handle this event to paint the filter panel manually
    gridView.CustomDrawFilterPanel += (s, e) => {
        GridView view = s as GridView;
        GridFilterPanelInfoArgs info = e.Info as DevExpress.XtraGrid.Drawing.GridFilterPanelInfoArgs;
        e.Cache.FillRectangle(Color.BlanchedAlmond, e.Bounds);
        e.Appearance.ForeColor = Color.DimGray;
        e.Appearance.DrawString(e.Cache, info.DisplayText, info.TextBounds);
        SkinGridFilterPanelPainter painter = e.Painter as SkinGridFilterPanelPainter;
        info.ActiveButtonInfo.CheckState = view.ActiveFilterEnabled ? CheckState.Checked : CheckState.Unchecked;
        ObjectPainter.DrawObject(e.Cache, painter.CheckPainter, info.ActiveButtonInfo);
        ObjectPainter.DrawObject(e.Cache, painter.ButtonPainter, info.CustomizeButtonInfo);
        ObjectPainter.DrawObject(e.Cache, painter.ButtonPainter, info.CloseButtonInfo);
        e.Handled = true;
    };
}
vb
Imports DevExpress.XtraGrid.Drawing

Private Sub Form3_Load1(ByVal sender As Object, ByVal e As EventArgs)
    CustomDrawFilterPanel(gridControl1, gridView1)
End Sub

Public Shared Sub CustomDrawFilterPanel(ByVal gridControl As GridControl, ByVal gridView As GridView)
    gridView.ActiveFilterString = String.Format("[{0}] > 2", "ID")

    ' Handle this event to paint the filter panel manually
    AddHandler gridView.CustomDrawFilterPanel, Sub(s, e)
        Dim view As GridView = TryCast(s, GridView)
        Dim info As GridFilterPanelInfoArgs = TryCast(e.Info, DevExpress.XtraGrid.Drawing.GridFilterPanelInfoArgs)
        e.Cache.FillRectangle(Color.BlanchedAlmond, e.Bounds)
        e.Appearance.ForeColor = Color.DimGray
        e.Appearance.DrawString(e.Cache, info.DisplayText, info.TextBounds)
        Dim painter As SkinGridFilterPanelPainter = TryCast(e.Painter, SkinGridFilterPanelPainter)
        info.ActiveButtonInfo.CheckState = If(view.ActiveFilterEnabled, CheckState.Checked, CheckState.Unchecked)
        ObjectPainter.DrawObject(e.Cache, painter.CheckPainter, info.ActiveButtonInfo)
        ObjectPainter.DrawObject(e.Cache, painter.ButtonPainter, info.CustomizeButtonInfo)
        ObjectPainter.DrawObject(e.Cache, painter.ButtonPainter, info.CloseButtonInfo)
        e.Handled = True
    End Sub
End Sub

See Also

Filter and Search

Custom Painting Basics

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace