DevExpress GridControl 部分用法

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方法。

posted on 2015-06-12 20:03  电子灵魂 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wordgao/p/4572463.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值