HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Thursday, July 19, 2012

WinForms Grid - How to Custom Draw Footer Cells

Nearly all visual aspects of the XtraGrid can be customized. In this video, you will learn how to custom draw the footer cells that contain summary values for specific columns.

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

2.       I’ll bind the grid to a data source by invoking its smart tag and clicking the “Add Project Data Source” link.

3.       I’ll use an existing Connection String for the CarsDB database.

4.       I click “Next” and select the “Cars” Table that will supply data to the grid.

5.       Finally, I click finish to complete the wizard.

6.       I run the Grid’s designer and switch to the columns page

7.       I highlight and remove the unnecessary columns.

8.       For purposes of this example, I’ll select the “HP” column, expand its SummaryItem property and set the SummaryType to “Sum”.

9.       I will do the same for the “Cylinder” column.

10.   And I’m done with the grid’s customization so I’ll close the designer.

11.   To display the footer, I select the grid view and set its OptionsView.ShowFooter property to “True”.

12.   Now I’m going to add some code to custom draw the footer cells we just enabled.

13.   This can be done using the CustomDrawFooterCell event of the grid view.

14.   I create a new handler for the event and add the following code to it.

15.   Notice that I need to add a reference to the System.Drawing.Drawing2D namespace.

16.   And I’m done!

17.   I run the application to see the results.

18.   You’ll see that the footer cells are now drawn with a raised border as well as a gradient background.

 

No comments:

Post a Comment