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

  • 相关阅读:
    修改Matlab的背景颜色
    lane车道连接规则
    用汇编语言输出Hello World!
    运用ISAPI_Rewrite将asp静态化应注意路径
    广州,佛山>黄岐生活资讯网生活信息发布
    最近使用网络电话,还比较便宜
    小心中中国移动“短号集群网”的招
    正规表达式的一些知识
    ubuntu 8.04下安装和使用systemtap
    应用程序框架设计之二:分层和层间数据传递(上)
  • 原文地址:https://www.cnblogs.com/wordgao/p/4572463.html
Copyright © 2020-2023  润新知