Monday 28 February 2011

LINQ EXAMPLE

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 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.
If these techniques don't suit your needs you can use the Appearance specific events that are more flexible.
Each of these events provides the Appearance parameter whose settings can be used to customize the background and foreground colors, gradient mode, text display options, etc.
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:
C#
VB
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.
C#
VB
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;
      }
   }
}

The following image shows the result. Note that unlike the previous example the gradient is applied to individual cells and not to entire rows.

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;

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 ObjectCollects, SQL, XML etc. Before you start reading this article, it is good to have look at the features supported by LINQ:
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
01_userclient_table.png
UserClients
02_user_table.png
LINQ structure
03_linq_structure.png
Note: In this article, all LINQ queries are performed in the LINQPAD application.