刚接触DevExpress第三方控件,把GridControl的常见用法整理一下,以供参考:

说明:

gcTest   GridControl

gvText    GridView

//隐藏最上面的GroupPanel  即去掉"Drag a Column Header Here To Group by that Column"         
            gvText.OptionsView.ShowGroupPanel = false;

  //修改最上面的GroupPanel
            gvText.GroupPanelText = "修改后的内容";

//单元格不可编辑
            gvText.OptionsBehavior.Editable = false;

//某列标题居中  0是列索引
            gvText.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

//某列内容居中  0是列索引
            gvText.Columns[0].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

//冻结列
            gvText.Columns[0].Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;

//自动改变行高适应内容
            gvText.OptionsView.RowAutoHeight = true;

   //显示自动筛选行
            gvText.OptionsView.ShowAutoFilterRow = false;

   //不显示字表信息
            gvText.OptionsView.ShowDetailButtons = false;
           
            //显示水平滚动条,自动列宽
             gvText.OptionsView.ColumnAutoWidth=false;

//自动调整列宽
            gvText.BestFitColumns();

            //禁用GridControl中单击列弹出右键菜单
            gvText.OptionsMenu.EnableColumnMenu = false;

            //禁用GridControl中列头的过滤器
             gvText.OptionsCustomization.AllowFilter = false;

            //禁止各列头移动
              gvText.OptionsCustomization.AllowColumnMoving = false;

            //禁止各列头排序
              gvText.OptionsCustomization.AllowSort = false;

            //禁止各列头改变列宽
                gvText.OptionsCustomization.AllowColumnResizing = false;

//根据绑定的数据源自动产生列,有时可以解决GridControl记录能获取而没有显示出来的问题
                 gvText.PopulateColumns();

//奇偶行变色
            gvText.OptionsView.EnableAppearanceEvenRow = true;
            gvText.OptionsView.EnableAppearanceOddRow = true;
            gvText.Appearance.EvenRow.BackColor = Color.Gray;
            gvText.Appearance.OddRow.BackColor = Color.GreenYellow;

  //特殊列设置      日期
            string strDate="yyyy-MM-dd HH:mm";
            RepositoryItemDateEdit ride = new RepositoryItemDateEdit();
            ride.DisplayFormat.FormatString = strDate;
            ride.EditFormat.FormatString = strDate;
            ride.EditMask = strDate;
            gvText.Columns["日期"].ColumnEdit = ride;

//列格式设置      decimal    价格  
            public const string MoneyFormatStr = "##,###,###,###,##0.00";
            RepositoryItemCalcEdit rice = new RepositoryItemCalcEdit();
            rice.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            rice.DisplayFormat.FormatString = MoneyFormatStr;            
            rice.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            rice.EditFormat.FormatString = MoneyFormatStr;
            rice.EditMask = MoneyFormatStr;
            gv.Columns["价格"].ColumnEdit = rice;

  //给单元格赋值
            gvText.SetRowCellValue(3, gvText.Columns["列名或列索引"],"要赋的值");
           
            //添加行
            gvText.AddNewRow();

//添加列
            DevExpress.XtraGrid.Columns.GridColumn col = new DevExpress.XtraGrid.Columns.GridColumn();
            col.Caption = "列标题";
            col.FieldName = "列字段值";
            col.Visible = true;
            col.VisibleIndex = gvText.Columns.Count;
            gvText.Columns.Add(col);
        /// <summary>
        /// 获取选定行指定列单元格的值
        /// </summary>
        /// <param name="str">指定列的列名</param>
        /// <returns>单元格的值</returns>
        public string GetCellValue(string str) {
            int[] pRows = this.gvText.GetSelectedRows();
            if (pRows.GetLength(0) > 0){           
                return gvText.GetRowCellValue(pRows[0], str).ToString();
            }
            else {
                return null;
            }       
        }

GridControl常见用法【转】的更多相关文章

  1. DevExpress 控件 GridControl常见用法

    刚接触DevExpress第三方控件,把GridControl的常见用法整理一下,以供参考: 说明: gcTest   GridControl gvText    GridView //隐藏最上面的G ...

  2. Linux中find常见用法

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  3. php中的curl使用入门教程和常见用法实例

    摘要: [目录] php中的curl使用入门教程和常见用法实例 一.curl的优势 二.curl的简单使用步骤 三.错误处理 四.获取curl请求的具体信息 五.使用curl发送post请求 六.文件 ...

  4. Guava中Predicate的常见用法

    Guava中Predicate的常见用法 1.  Predicate基本用法 guava提供了许多利用Functions和Predicates来操作Collections的工具,一般在 Iterabl ...

  5. find常见用法

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  6. iOS 开发多线程篇—GCD的常见用法

    iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...

  7. iOS开发多线程篇—GCD的常见用法

    iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...

  8. [转]EasyUI——常见用法总结

    原文链接: EasyUI——常见用法总结 1. 使用 data-options 来初始化属性. data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我 ...

  9. NSString常见用法总结

    //====================NSStirng 的常见用法==================== -(void)testString { //创建格式化字符串:占位符(由一个%加一个字 ...

随机推荐

  1. 循序渐进学.Net Core Web Api开发系列【2】:利用Swagger调试WebApi

    系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.概述 既然前后端 ...

  2. GPU安装

    安装驱动 https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_d ...

  3. RelativeSource的用法

    绑定自身的数据 <Style TargetType="Button"> <Setter Property="Width" Value=&quo ...

  4. Reveal逆向工程:分析任意iOS应用的UI界面

    在iOS逆向工程中,Reveal扮演着重要角色,一般情况下,Reveal在iOS开发过程中可以分析UI界面的状态,同样也可以应用于分析其他任意的App.特别是对于初学者来说,去了解其他优秀App的界面 ...

  5. OpenVPN推送默认路由表

    根据官方Server配置文件:https://github.com/OpenVPN/openvpn/blob/master/sample/sample-config-files/server.conf ...

  6. [原创]SOAPUI工具介绍

    [原创]SOAPUI工具介绍 一 官方网站:http://www.soapui.org/二 下载地址:http://sourceforge.net/projects/soapui/files/三 so ...

  7. MDK5 and STM32Cube

    D:\Workspace\........\RTE\Device>STM32CubeMX.exe -s project.script -tpl_path C:\Keil5\ARM\Pack\Ke ...

  8. 使用Sublime text 3打造一个小巧但强大的Go语言开发IDE

    版权声明:欢迎转载,转载请注明出处! https://blog.csdn.net/iTaacy/article/details/76716049 使用Sublime text 3打造一个小巧但强大的G ...

  9. jQuery 事件方法大全-超全的总结

    jquery经常使用的事件: /*     on     off     hover     blur     change     click     dblclick     focus     ...

  10. The main reborn ASP.NET MVC4.0: using CheckBoxListHelper and RadioBoxListHelper

    The new Helpers folder in the project, to create the CheckBoxListHelper and RadioBoxListHelper class ...