DevExpress GridControl使用方法總結

1、如何解決單擊記錄整行選中的問題html

View->OptionsBehavior->EditorShowMode 設置爲:Clickexpress

2、如何新增一條記錄this

(1)、gridView.AddNewRow()翻譯

(2)、實現gridView_InitNewRow事件htm

3、如何解決GridControl記錄能獲取而沒有顯示出來的問題排序

gridView.populateColumns();事件

4、如何讓行只能選擇而不能編輯(或編輯某一單元格)get

(1)、View->OptionsBehavior->EditorShowMode 設置爲:Clickstring

(2)、View->OptionsBehavior->Editable 設置爲:falseit

5、如何禁用GridControl中單擊列彈出右鍵菜單

設置Run Design->OptionsMenu->EnableColumnMenu 設置爲:false

6、如何隱藏GridControl的GroupPanel表頭

設置Run Design->OptionsView->ShowGroupPanel 設置爲:false

7、如何禁用GridControl中列頭的過濾器

過濾器以下圖所示:

DevExpress GridControl使用方法總結

設置 Run Design->OptionsCustomization->AllowFilter 設置爲:false

8、如何在查詢獲得0條記錄時顯示自定義的字符提示/顯示

如圖所示:

DevExpress GridControl使用方法總結

方法以下:

//When no Records Are Being Displayed
private void gridView1_CustomDrawEmptyForeground(object sender, CustomDrawEventArgs e)
{
     //方法一(此方法爲GridView設置了數據源綁定時,可用) 
     ColumnView columnView = sender as ColumnView;
     BindingSource bindingSource = this.gridView1.DataSource as BindingSource;
     if(bindingSource.Count == 0)
     {
          string str = "沒有查詢到你所想要的數據!";
          Font f = new Font("宋體", 10, FontStyle.Bold);
          Rectangle r = new Rectangle(e.Bounds.Top + 5, e.Bounds.Left + 5, e.Bounds.Right - 5, e.Bounds.Height - 5);
          e.Graphics.DrawString(str, f, Brushes.Black, r);
     }
     //方法二(此方法爲GridView沒有設置數據源綁定時,使用,通常使用此種方法)  
     if (this._flag)
     {
          if (this.gridView1.RowCount == 0)
          {
               string str = "沒有查詢到你所想要的數據!";
               Font f = new Font("宋體", 10, FontStyle.Bold);
               Rectangle r = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);
               e.Graphics.DrawString(str, f, Brushes.Black, r);
          }
     }
}

9、如何顯示水平滾動條?

設置this.gridView.OptionsView.ColumnAutoWidth = false;

10、如何定位到第一條數據/記錄?

設置 this.gridView.MoveFirst()

11、如何定位到下一條數據/記錄?

設置 this.gridView.MoveNext()

12、如何定位到最後一條數據/記錄?

設置 this.gridView.MoveLast()

十3、設置成一次選擇一行,而且不能被編輯

this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
this.gridView1.OptionsBehavior.Editable = false;
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;

十4、如何顯示行號?

this.gridView1.IndicatorWidth = 40; 
//顯示行的序號 
private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
     if (e.Info.IsRowIndicator && e.RowHandle>=0)
     {
          e.Info.DisplayText = (e.RowHandle + 1).ToString();
     }
}

十5、如何讓各列頭禁止移動?

設置gridView1.OptionsCustomization.AllowColumnMoving = false;

十6、如何讓各列頭禁止排序?

設置gridView1.OptionsCustomization.AllowSort = false;

十7、如何禁止各列頭改變列寬?

設置gridView1.OptionsCustomization.AllowColumnResizing = false;

本站文章除註明轉載外,均爲本站原創或翻譯
歡迎任何形式的轉載,但請務必註明出處,尊重他人勞動成果
轉載請註明:文章轉載自:DevExpress控件中文網 [ http://www.devexpresscn.com/]
本文地址: http://www.devexpresscn.com/news/DevExpress-news-90.html
相關文章
相關標籤/搜索