DevExpress GridControl 部分用法

來源:互聯網
上載者:User

標籤:

1、GridControl賦值:this.GridControl1.DataSouce=dt;

2、GridContro總合計及分組合計:

    常規總合計直接RunDesigner-Group Summary Items

    DisplayFormat 設定顯示格式如:{0:P}表示顯示為百分比符號模式。如資料來源中為0.5。表示出來為50%

    FieldName 設定顯示的對應列

    ShowInGroupColumnFooter 在那一列下面顯示

    SummaryType 合計方式。選擇Custom表示自訂。CustomSummaryCalculate事件可處理

//Footer行自訂欄合計  GridView view = sender as GridView;  if (e.Item == view.Columns["RateZk"].SummaryItem)  {    decimal x = Convert.ToDecimal(view.Columns["RetailFAmount"].SummaryItem.SummaryValue);    decimal y = Convert.ToDecimal(view.Columns["RetailAmount"].SummaryItem.SummaryValue);    view.Columns["RateZk"].SummaryItem.DisplayFormat = "{0:P}";    if (y != 0)    e.TotalValue = x / y;    else    e.TotalValue = 0;  }
//分組行自訂合計列  if (e.IsGroupSummary) {    Hashtable ht = view.GetGroupSummaryValues(e.GroupRowHandle);    foreach (DictionaryEntry entry in ht)    {      GridGroupSummaryItem sumItem = entry.Key as GridGroupSummaryItem;      if (sumItem.FieldName.Equals("RetailFAmount"))         retailFAmount = Convert.ToDecimal(entry.Value);    }               if (e.Item.ToString().Contains(view.Columns["RateZk"].SummaryItem.FieldName))           e.TotalValue = retailFAmount

3、GridContro匯出Excel操作:

SaveFileDialog saveFileDialog = new SaveFileDialog();   saveFileDialog.Title = "匯出Excel";   saveFileDialog.Filter = "Excel檔案(*.xls)|*.xls";   DialogResult dialogResult = saveFileDialog.ShowDialog(this);   if (dialogResult == DialogResult.OK)   {     this.gvbrowse.OptionsPrint.AutoWidth = false; //設定匯出的Excel自動調整列寬,列寬和控制項的列寬一致     this.gcbrowse.ExportToXls(saveFileDialog.FileName);     //this.gcbrowse.ExportToXlsOld(saveFileDialog.FileName);//這個方法預設會自動調整列寬,但是office10以上版本有的會報錯     DevExpress.XtraEditors.XtraMessageBox.Show("儲存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);     this.gvbrowse.OptionsPrint.AutoWidth = true;    }

4、GridControl列要顯示百分比符號:

Run Designer-Columns列 FormatType="Numeric" FormatString="p"

5、gridView1.OptionsView.ShowGroupPanel = false; 不顯示分組面板

6、gridView1.OptionsBehavior.Editable=false; 資料唯讀

7、設定列時間格式:Formatstring="yyyy-MM-dd HH:ss:mm"; FormatType="Numeric";

     設定列數字格式:Formatstring="N2";(資料格式:F表浮點,N表整數,數字表示保留幾位小數。N2等同於F2)

     具體設定參見輸入控制項的屬性的Mask屬性

9、將所有組展開代碼:gridView1.ExpandAllGroups();

10、自動調整所有欄位寬度  this.gridView1.BestFitColumns();

      調整某欄欄位寬度  this.gridView1.Columns[n].BestFit();

11、顯示捲軸:gridView1.OptionsView.ColumnAutoWidth屬性是true,即各列的寬度自動調整,你把它設成false,就會出現了。

12、選擇某行後擷取當前表格式資料  this.textBox1.Text = gridView2.GetDataRow(e.RowHandle)["列名"].ToString();

13、設定奇、偶行交替顏色

  • OptionsView.EnableAppearanceEvenRow = true;OptionsView.EnableAppearanceOddRow = true;
  • 設定Appearance.EvenRow.BackColor和Appearance.OddRow.BackColor

14、根據繫結資料源自動產生列  gridView1.PopulateColumns();

15、設定選中一行 Grivview->OptionsBehavior->EditorShowMode 設定為:Click

16、出現GridControl加入選擇列後,擷取選中值出錯的情況。加入如下代碼。

      gvresult.EndInit();gvresult.CloseEditor(); gvresult.UpdateCurrentRow()

17、設定GridControl唯讀。選擇的列可複製。單獨設定GridControl列ReadOnly=true

18、設定GridView自動查詢列 gridView1.OptionsView.ShowAtuoFilterRow=true

19、判斷選中行:if (!gvbrowse.IsValidRowHandle(gvbrowse.FocusedRowHandle)) return;

       string x=(gvbrowse.GetDataRow(gvbrowse.FocusedRowHandle)["CID"]).ToString();

20、GridControl加入的checkbox要點很多次才能選中。在控制項裡找到OptionsBehavior下面的EditorShowMode屬性設定成MouseDown  

21、擷取GridControl篩選後的資料。

第一種情況: 
DataView dv = this.gridView1.DataSource as DataView; DataTable dt= dv.Table; DataRow[] rows= dt.Select(this.gridView1.RowFilter);

第二種情況:

BindingSource dv = this.gvwResult.DataSource as System.Windows.Forms.BindingSource;

DataTable dt = dv.DataSource as DataTable;
DataRow[] filteredRows = dt.Select(this.gvwResult.RowFilter);
註:gridview的屬性RowFilter恰好適合DataTable的Select方法。

DevExpress 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.