[轉]GridControl各種事件

來源:互聯網
上載者:User

標籤:

 

[csharp] view plaincopyprint?
  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


代碼:

[csharp] view plaincopyprint?
  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


代碼:

[csharp] view plaincopyprint?
  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

[轉]GridControl各種事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.