Monday, 28 February 2011
Customizing Appearances of Individual Rows and Cells
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:
| ||||||
using DevExpress.XtraGrid.Views.Grid; private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) { GridView View = sender as GridView; if(e.RowHandle >= 0) { string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Category"]); if(category == "Beverages") { e.Appearance.BackColor = Color.Salmon; e.Appearance.BackColor2 = Color.SeaShell; } } } |
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.
| ||||||
using DevExpress.XtraGrid.Views.Grid; // ... private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) { GridView View = sender as GridView; if(e.Column.FieldName == "Count" || e.Column.FieldName == "Unit Price") { string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Category"]); if(category == "Seafood") { e.Appearance.BackColor = Color.DeepSkyBlue; e.Appearance.BackColor2 = Color.LightCyan; } } } |
Sunday, 27 February 2011
Gridview - Displaying color
dataGridView1.Rows[0].DefaultCellStyle.BackColor = System.Drawing.Color.Orange;
dataGridView1.Rows[1].DefaultCellStyle.BackColor = System.Drawing.Color.Red;
Friday, 25 February 2011
Monday, 21 February 2011
Learn SQL to LINQ (Visual Representation)
Introduction
A lot of developers moving towards the new LINQ to SQL find it difficult to write SQL queries in C# to query data using LINQ. LINQ is a query language which is integrated in C# to query data from
ObjectCollect
s, SQL, XML etc. Before you start reading this article, it is good to have look at the features supported by LINQ:- Implicitly typed local variables
- Extension Methods
- Anonymous types
- Lambda Expressions
- Object and collection initialization
Here in this artcile, I am going to discuss the basic SQL queries and the LINQ queries similar to SQL queries, with visual representations of the LINQ queries. Before I start discussing, here is the structure of the table I am using for this article:
Users
UserClients
LINQ structure
Note: In this article, all LINQ queries are performed in the LINQPAD application.
Subscribe to:
Posts (Atom)