Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Data Binding
   [Expand]Views
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Filter and Search
   [Expand]Summaries
   [Expand]Focus and Selection Handling
    Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Collapse]Appearance and Conditional Formatting
    [Collapse]Custom Painting
      Custom Painting Basics
      Custom Painting Scenarios
      Elements that Can Be Custom Painted
      Manually Invalidating Controls
    [Expand]Alpha Blending and Background Images
    Split Presentation
    Row Preview Sections
    Scrolling
   [Expand]Batch Modifications
   [Expand]Hit Information
    Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Custom Painting Scenarios

Custom draw events provide complete control over the appearance of grid elements. This document provides examples illustrating common scenarios for custom draw events. For basic information on custom painting in Grid Control, refer to the Custom Painting Basics topic.

Note

Custom painting and alpha blending features are not applied to the print and export versions of the Grid Control.

Note

In specific paint themes (e.g., skins and Office2003), you are not able to change the background of some elements. Changing the background of these elements via the Appearance parameter of custom draw events is also not supported.

There are three main scenarios for custom draw event usage.

 

Expanded Manual Element Rendering

Custom draw events allow you to manually render grid elements using the methods provided by the event's CustomDrawEventArgs.Graphics and CustomDrawEventArgs.Appearance objects. These objects' methods allow you to draw various graphics primitives (lines, rectangles, ellipses, images, etc.). When performing manual element rendering, you typically need to set the event's CustomDrawEventArgs.Handled parameter to true. Otherwise, the default painting mechanism will be invoked after event execution, and it will override your rendering.

 

The following example demonstrates how to use the GridView.CustomDrawCell event to custom paint the RequiredDate column's cells. If a cell refers to the current or following date, its background is filled with a gradient brush. If the cell contains a date that is greater than the current date, the cell will display the number of days left until the specified date. The appearance of the other cells is not affected.

The image below shows the result.

Expanded Combining Default Painting and Custom Painting

The following scenario allows you to paint custom information over the default rendering. To accomplish this task, first invoke the default painting mechanism for an element using the CustomDrawEventArgs.DefaultDraw method. Then, you can paint additional information over the default rendering using the methods of the event's CustomDrawEventArgs.Graphics and CustomDrawEventArgs.Appearance properties.

Before invoking the default painting mechanism, you can modify an element's display information. The default rendering mechanism, when invoked, will apply these changes. For instance, you can modify the appearance of an element using the event's CustomDrawEventArgs.Appearance property. Custom draw events for some elements (filter panel, band and column headers, view footer, group footer, group rows, preview section, row indicator and footer cells) provide the Info parameter, which contains element-specific view information. For these events, you can change the Info object's properties to customize an element's display text or change the boundaries of inner elements. If an event contains a DisplayText property, you can set it to a custom value before invoking the default rendering.

A call to the CustomDrawEventArgs.DefaultDraw method automatically sets the event's Handled parameter to true. This prevents the default painting mechanism from being re-invoked after event execution.

Note that modifying the boundaries of elements or inner elements changes the View layout. If you need to change the boundaries of elements for the purpose of custom painting, you should restore the boundaries immediately after the default painting mechanism is invoked.

 

The following example shows how to handle the GridView.CustomDrawCell event to paint a custom image over the default rendering for specific cells.

For cells containing 0 in the "Units In Stock" column, a custom warning icon is displayed over the default rendering. The default rendering is performed using the CustomDrawEventArgs.DefaultDraw method.

The result is shown below:

Expanded Customizing Element Display Information for Default Rendering

When handling a custom draw event, you can change an element's view information (e.g., appearance or content) and set the event's CustomDrawEventArgs.Handled property to false (the default value). In this case, the default rendering will automatically be invoked after the event execution. The painting mechanism will use the modified view information to render the element.

The following table describes custom draw events that allow you to customize an element's display information.

Custom draw event Allows you to ...

GridView.CustomDrawColumnHeader

ColumnView.CustomDrawFilterPanel

GridView.CustomDrawFooter

GridView.CustomDrawFooterCell

GridView.CustomDrawGroupRow

GridView.CustomDrawRowFooter

GridView.CustomDrawRowFooterCell

GridView.CustomDrawRowIndicator

GridView.CustomDrawRowPreview

BandedGridView.CustomDrawBandHeader

LayoutView.CustomDrawCardBackground

- Change the display information via the event's Info parameter.
The Info object allows you to change the display text (if it is available for the element being painted).
Avoid changing the boundaries of the inner elements as this may corrupt the View's layout.

- Provide a custom appearance using the event's Appearance property.

GridView.CustomDrawCell

CardView.CustomDrawCardFieldValue

CardView.CustomDrawCardFieldCaption

CardView.CustomDrawCardCaption

LayoutView.CustomDrawCardCaption

LayoutView.CustomDrawCardFieldCaption

LayoutView.CustomDrawCardFieldValue

- Dynamically supply custom display text via the DisplayText/CardCaption parameter.

- Provide a custom appearance using the event's Appearance property.

 

The following example demonstrates how to specify a custom background for footer cells using the GridView.CustomDrawFooterCell event. The default appearance settings specified by the View's GridViewAppearances.FooterPanel property will be ignored.

The image below shows the result.

Expanded See Also

How would you rate this topic?​​​​​​​