1. 程式人生 > >DevExpress GridControl 常用事件

DevExpress GridControl 常用事件

 事件

根據狀態顯示要設定行的顏色

privatevoid gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)

        {

GridView View = senderasGridView;

if (e.RowHandle >= 0)

            {

string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["AUTHSTATUSDESC"]);

if (category ==

"認證未通過")

                {

                    e.Appearance.BackColor =Color.Crimson;

                    e.Appearance.BackColor2 =Color.SeaShell;

                }

elseif (category == "認證通過")

                {

                    e.Appearance.BackColor =Color.DeepSkyBlue;

                    e.Appearance.BackColor2 =

Color.SeaShell;

                }

            }

        }

雙擊行時,顯示對應的TabPage頁

privatevoid gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)

        {

if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 2

            {

                XtraTabControl1.SelectedTabPage = pageDetail;

            }

        }

此功能同DoubleClick事件

privatevoidgridView1_DoubleClick(object sender,EventArgs e)

        {

XtraTabControl1.SelectedTabPage = pageDetail;

        }

如何在查詢得到0條記錄時顯示自定義的字元提示/顯示

privatevoid gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)

        {

if (this.gridView1.RowCount == 0)

            {

string str = "沒有符合條件的資料!";

                System.Drawing.Font f = new System.Drawing.Font("宋體", 10, FontStyle.Bold);

Rectangle r = newRectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);

                e.Graphics.DrawString(str, f, Brushes.Black, r);

            }

        }

顯示水平滾動條

設定this.gridView1.OptionsView.ColumnAutoWidth = false;

 設定Run Design->OptionsView->ColumnAutoWidth 設定為:false

定位到第一條資料/記錄?

設定 this.gridView.MoveFirst()

定位到下一條資料/記錄?

設定 this.gridView.MoveNext()

定位到最後一條資料/記錄?

設定 this.gridView.MoveLast()