zoukankan      html  css  js  c++  java
  • [转]GridControl各种事件

    1. <span style="white-space: pre;">    </span>private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)  
    2.         {  
    3.             if (e.Button == MouseButtons.Left)  
    4.             {  
    5.                 //鼠标的那个按钮按下  
    6.             }  
    7.             if (e.Clicks == 2)  
    8.             {  
    9.                  //鼠标点击次数  
    10.             }  
    11.             if (e.Delta > 0)  
    12.             {  
    13.                 //鼠标滚轮滚动方向  
    14.             }  
    15.             if (e.X > 0 & e.Y > 0)  
    16.             {  
    17.                 //鼠标的坐标  
    18.             }  
    19.             if (e.RowHandle > 0)  
    20.             {  
    21.                 //点击的行号  
    22.             }  
    23.             if (e.CellValue != null)  
    24.             {  
    25.                 //点击的单元格中的值  
    26.             }  
    27.             if (e.Column != null)  
    28.             {  
    29.                 //点击的单元格所属列信息  
    30.             }  
    31.         }  
    32.   
    33. <span style="white-space: pre;">    </span>private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)  
    34.         {  
    35.             if (e.Button == MouseButtons.Left)  
    36.             {  
    37.                 //鼠标的那个按钮按下  
    38.             }  
    39.             if (e.Clicks == 2)  
    40.             {  
    41.                 //鼠标点击次数  
    42.             }  
    43.             if (e.Delta > 0)  
    44.             {  
    45.                 //鼠标滚轮滚动方向  
    46.             }  
    47.             if (e.X > 0 & e.Y > 0)  
    48.             {  
    49.                 //鼠标的坐标  
    50.             }  
    51.             if (e.RowHandle > 0)  
    52.             {  
    53.                 //点击的行号  
    54.             }  
    55.         }  
    private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    //鼠标的那个按钮按下
                }
                if (e.Clicks == 2)
                {
                     //鼠标点击次数
                }
                if (e.Delta > 0)
                {
                    //鼠标滚轮滚动方向
                }
                if (e.X > 0 & e.Y > 0)
                {
                    //鼠标的坐标
                }
                if (e.RowHandle > 0)
                {
                    //点击的行号
                }
                if (e.CellValue != null)
                {
                    //点击的单元格中的值
                }
                if (e.Column != null)
                {
                    //点击的单元格所属列信息
                }
            }
    
    private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    //鼠标的那个按钮按下
                }
                if (e.Clicks == 2)
                {
                    //鼠标点击次数
                }
                if (e.Delta > 0)
                {
                    //鼠标滚轮滚动方向
                }
                if (e.X > 0 & e.Y > 0)
                {
                    //鼠标的坐标
                }
                if (e.RowHandle > 0)
                {
                    //点击的行号
                }
            }
    

    重新绘制列样式事件:gridView1_CustomDrawCell


    代码:

    1. private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)  
    2. {  
    3.     if (e.Column.FieldName == "数据")  
    4.     {  
    5.         GridCellInfo GridCellInfo = e.Cell as GridCellInfo;  
    6.         if (GridCellInfo.IsDataCell && double.Parse(GridCellInfo.CellValue.ToString()) <= -30)  
    7.             e.Appearance.BackColor = Color.Yellow;  
    8.         else if (GridCellInfo.IsDataCell && double.Parse(GridCellInfo.CellValue.ToString()) > -30   
    9.             && double.Parse(GridCellInfo.CellValue.ToString()) <= -50)  
    10.             e.Appearance.BackColor = Color.Green;  
    11.         else if (GridCellInfo.IsDataCell && double.Parse(GridCellInfo.CellValue.ToString()) > -50)  
    12.             e.Appearance.BackColor = Color.Red;  
    13.     }  
    14. }  
    private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
    {
        if (e.Column.FieldName == "数据")
        {
            GridCellInfo GridCellInfo = e.Cell as GridCellInfo;
            if (GridCellInfo.IsDataCell && double.Parse(GridCellInfo.CellValue.ToString()) <= -30)
                e.Appearance.BackColor = Color.Yellow;
            else if (GridCellInfo.IsDataCell && double.Parse(GridCellInfo.CellValue.ToString()) > -30 
                && double.Parse(GridCellInfo.CellValue.ToString()) <= -50)
                e.Appearance.BackColor = Color.Green;
            else if (GridCellInfo.IsDataCell && double.Parse(GridCellInfo.CellValue.ToString()) > -50)
                e.Appearance.BackColor = Color.Red;
        }
    }
    

    重新计算备注事件:gridView1_CalcPreviewText


    代码:

    1. private void gridView1_CalcPreviewText(object sender, DevExpress.XtraGrid.Views.Grid.CalcPreviewTextEventArgs e)  
    2. {  
    3.     DataRow dr = gridView1.GetDataRow(e.RowHandle);  
    4.     e.PreviewText = dr["name"].ToString() + " : " + dr["aihao"].ToString();  
    5. }  
    private void gridView1_CalcPreviewText(object sender, DevExpress.XtraGrid.Views.Grid.CalcPreviewTextEventArgs e)
    {
        DataRow dr = gridView1.GetDataRow(e.RowHandle);
        e.PreviewText = dr["name"].ToString() + " : " + dr["aihao"].ToString();
    }
    

    注意:GridView中大多数事件我们都会并且必须用到e这个参数,我们可以从e这个参数中获取很多信息,包括单元格、列、行、表格、GridControl的信息。我们要根据事件的意义来了解这个e是单元格级别的,或是行级别的,或是列级别的等,因为我们可以获取e的层级以上的信息,层级以下的信息就不能获取了。

    e中的属性都是大同小异,其中最常用的是e.RowHandle这个属性,它代表行号的意思,通过gridView1.GetDataRow(e.RowHandle)方法可以获得这一行的数据行DataRow;并以此来做很多操作。

    上述我们也说过组行的RowHandle为负数,我们通过GetDataRow获取数据行是错误的,这时我们通过gridView1.GetDataRowHandleByGroupRowHandle(e.RowHandle);方法来转化,这时得到的数据行是该组的第一行数据。在此我们需特别注意。如果加入上述转换,我们选择数据时每组第一行数据就会重复,我们要做去重复处理。

    皮肤设置



     
    原文地址:http://blog.csdn.net/nanchuan/article/details/7770577
  • 相关阅读:
    Begin Example with Override Encoded SOAP XML Serialization
    State Machine Terminology
    How to: Specify an Alternate Element Name for an XML Stream
    How to: Publish Metadata for a WCF Service.(What is the Metadata Exchange Endpoint purpose.)
    Beginning Guide With Controlling XML Serialization Using Attributes(XmlSerializaiton of Array)
    Workflow 4.0 Hosting Extensions
    What can we do in the CacheMetaData Method of Activity
    How and Why to use the System.servicemodel.MessageParameterAttribute in WCF
    How to: Begin Sample with Serialization and Deserialization an Object
    A Test WCF Service without anything of config.
  • 原文地址:https://www.cnblogs.com/qvbrgw/p/4746930.html
Copyright © 2011-2022 走看看