DevExpress GridView Summary (i.)

Source: Internet
Author: User

One: The first column shows the line number Customdrawrowindicator

This.gridViewDevice.IndicatorWidth = 40;
This.gridviewdevice. customdrawrowindicator + = new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler ( Gridviewdevice_customdrawrowindicator);

void Gridviewdevice_customdrawrowindicator (object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.info.isrowindicator && e.rowhandle >= 0)
{
E.info.displaytext = convert.tostring (Convert.ToInt32 (e.rowhandle.tostring ()) + 1);
}}

Two: Do not show different background color RowStyle

private void Gridview1_rowstyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
if (e.rowhandle >= 0)
{
String category = view. Getrowcelldisplaytext (E.rowhandle, view. columns[" field name "]);
if (category = = " condition of the display Color ")
{
E.appearance.backcolor = Color.lightgreen;
}
}}

Three: Different cells display different background color Rowcellstyle

private void Gridview1_rowcellstyle (object sender, Rowcellstyleeventargs e)
{
GridView View = sender as GridView;
if (E.column.fieldname = = " bound field ")
{
String category = View.getrowcelldisplaytext (E.rowhandle, view.columns[" field name "]);
if (category = = " meet field Conditions ")
{
E.appearance.backcolor = color.lightcoral;
E.appearance.backcolor2 = Color.lightpink;
}}}

Four: Add Column icon Customunboundcolumndata

Add icon column, FieldName set to Image

Hashtable Images = new Hashtable (); Icon Collection

private void Gridview1_customunboundcolumndata (object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (E.column.fieldname = = "Image" && e.isgetdata)
{
String Condition = (string) ((DataRowView) e.row) [ lookup field ]. ToString ();
String fileName = "1.png";

Switch ( conditional )
{
Case "1":
FileName = "1.png";
Break
Case "2":
FileName = "2.png";
Break
}

if (! Images.containskey (FileName))
{
Image img = null;
Try
{
String FilePath = System.IO.Path.Combine (Application.StartupPath.ToString (), @ "Resource\icon", fileName);
img = Image.FromFile (filePath);
}
catch{}
Images.add (FileName, IMG);
}
E.value = Images[filename];
}
}

DevExpress GridView Summary (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.