Source : http://documentation.devexpress.com/#WindowsForms/CustomDocument758
The XtraGrid from version 3 onwards can be customized using the Appearance technology. This document demonstrates how to specify appearance settings for individual rows and cells.
The following image shows the result. Note that unlike the previous example the gradient is applied to individual cells and not to entire rows.
The XtraGrid from version 3 onwards can be customized using the Appearance technology. This document demonstrates how to specify appearance settings for individual rows and cells.
The Basics of Customizing the Appearances of Rows and Cells
XtraGrid provides a number of methods that can be used to customize the appearance of rows and cells.
- The GridViewAppearances.Row property can be used to provide common appearance settings for all rows (and thus cells) in a Grid View. For Card Views, theCardViewAppearances.Card property should be used instead.
- The GridViewAppearances.EvenRow and GridViewAppearances.OddRow gives you the ability to separately customize the even and odd rows in a Grid View.
- The GridViewAppearances.FocusedRow, GridViewAppearances.FocusedCell, GridViewAppearances.SelectedRow and GridViewAppearances.HideSelectionRow properties can be used to customize the appearance of the focused row, cell and selected rows.
- A column's GridColumn.AppearanceCell property can be used to customize the appearance of cells residing within a particular column. See the Customizing Appearances of Individual Columns, Card Fields and Bands topic for more information.
- Using Style Format Conditions is a simple way to customize the appearances of specific rows based upon a custom condition.
If these techniques don't suit your needs you can use the Appearance specific events that are more flexible.
- The GridView.RowStyle event. This can be handled to customize the appearance of individual rows. It is fired before the GridView.RowCellStyle event.
- The GridView.RowCellStyle event allows a specific cell's appearance to be customized.
- The GridView.CustomDrawCell event can be used in the same manner as the GridView.RowCellStyle event. See the Custom Painting Basics document for more details on custom drawing events.
Customizing the Appearances of Rows
In the following example the GridView.RowStyle event is handled to customize the appearance of rows which have the value "Beverages" in the Category column. These rows are painted using gradient filling. The starting and ending gradient colors are specified via the AppearanceObject.BackColor and AppearanceObject.BackColor2 properties of the event's RowStyleEventArgs.Appearance parameter.
The result is displayed below. Note that the gradients are applied to the entire rows and not to individual cells:
| ||||||
Customizing the Appearances of Cells
The following example demonstrates using the GridView.RowCellStyle event. This event is fired for each cell in a Grid View and thus it has Column and RowHandle parameters that identify the cell being painted.
In the example below the appearance of cells in the "Count" and "Unit Price" columns are customized if they reside within rows that contain the "Seafood" string in the "Category" column.
| ||||||
C# customize gridview appearance
ReplyDelete