HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Thursday, July 19, 2012

WinForms Grid - How to Draw the Sort and Filter Buttons When Custom Painting

In this video, you will learn how to custom paint the column headers as well as how to redraw the standard filter and sort buttons using the default painting mechanism.

So let’s get started…

1.       Starting from a new WinForms application, I drop an XtraGrid control onto the form and dock it to its parent.

2.       I switch to code view.

3.       In “Form1.cs”, I add a small class to store my data.

4.       For the purposes of this example, I’m going to use a simple list as my data source.

5.       In the form’s constructor, I create a field to hold the list of data I’m using.

6.       Next, I create some test data and bind it to the grid.

7.       To apply custom painting to the column headers, I select the grid view and create a handler for its CustomDrawColumnHeader event.

8.       This event is raised each time a column header is about to be painted.

9.       Here I will add the following code.

10.   I am using a gradient going from White to LightCyan to fill the background of the header.

11.   I set the Handled property to true so that no default processing occurs for this event.

12.   Now, I run the application.

13.   You can see that the column headers have been painted correctly; however the sort and filter buttons are missing from them.

14.   I close the application and return to Visual Studio.

15.   Back in code view, I add the following code to the CustomDrawColumnHeader event handler.

16.   This will use the default painting mechanism to draw the standard filter and sort buttons on the column headers.

17.   And I’m done!

18.   I run the application again to see the results.

19.   Now, the sort and filter buttons are drawn over my custom gradient background.

 

No comments:

Post a Comment