DevExpress GridControl使用方法總結

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

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

二、如何新增一條記錄

(1)、gridView.AddNewRow()

(2)、實現gridView_InitNewRow事件

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

gridView.populateColumns();

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

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

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

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

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

六、如何隱藏GridControl的GroupPanel表頭

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

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

過濾器如下圖所示:

DevExpress GridControl使用方法總結

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

八、如何在查詢得到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);
}
}
}

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

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

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

設置 this.gridView.MoveFirst()

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

設置 this.gridView.MoveNext()

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

設置 this.gridView.MoveLast()

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

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

十四、如何顯示行號?

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();
}
}

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

設置gridView1.OptionsCustomization.AllowColumnMoving = false;

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

設置gridView1.OptionsCustomization.AllowSort = false;

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

設置gridView1.OptionsCustomization.AllowColumnResizing = false;

原文地址:http://www.evget.com/zh-CN/info/catalog/16893.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章