GridControl 二次封装,自定义颜色样式风格

1、自定义颜色格式,分组,筛选

1、封装类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gridView
{
    public class GridControlEx : DevExpress.XtraGrid.GridControl
    {
        public DevExpress.XtraGrid.Views.Grid.GridView gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView();
        public GridControlEx()
        {
            this.Dock = System.Windows.Forms.DockStyle.Fill;
        }

        public void InitView()
        {
            this.gridView1 = (DevExpress.XtraGrid.Views.Grid.GridView)this.ViewCollection[0];
            this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView1_CustomDrawRowIndicator);
            gridView1.PaintStyleName = "Flat";   //设置外观样式
            gridView1.IndicatorWidth = 50;
            gridView1.OptionsView.ShowColumnHeaders = true;       //显示列标题
            gridView1.OptionsView.ShowIndicator = true;          // 不显示行标题
            gridView1.OptionsView.ShowGroupPanel = true;          // 显示分组panel
            gridView1.OptionsCustomization.AllowGroup = true;     //是否允许分组
            gridView1.OptionsView.ShowGroupedColumns = true;     //显示分组的列
            gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;   //是否显示过滤面板
            gridView1.OptionsCustomization.AllowFilter = true;                      //是否允许过滤
            gridView1.OptionsView.ShowAutoFilterRow = true;  //显示筛选列
            gridView1.OptionsCustomization.AllowColumnMoving = true;                //是否允许移动列
            gridView1.OptionsCustomization.AllowColumnResizing = false;              //是否允许调整列宽

            gridView1.OptionsCustomization.AllowSort = true;                          //是否允许排序

            gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;           //是否允许选中单元格
            //允许选中行,不允许编辑
            gridView1.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            gridView1.OptionsBehavior.Editable = false;                               //是否允许用户编辑单元格

            gridView1.OptionsView.EnableAppearanceEvenRow = true;                    //是否启用偶数行外观
            gridView1.OptionsView.EnableAppearanceOddRow = true;                     //是否启用奇数行外观
            gridView1.OptionsMenu.EnableColumnMenu = false;                          //禁用列标题右键菜单

            // gridView1.ClearSorting();//禁止排序

            DevExpress.XtraGrid.Views.Grid.GridViewAppearances Appearance1 = new DevExpress.XtraGrid.Views.Grid.GridViewAppearances(gridView1);

            //列标题颜色:System.Drawing.Color.FromArgb(((int)(((byte)(198)))), ((int)(((byte)(232)))), ((int)(((byte)(243))))); 

            //奇数行
            Appearance1.EvenRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(249)))), ((int)(((byte)(254)))));
            Appearance1.EvenRow.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            //偶数行
            Appearance1.OddRow.BackColor = System.Drawing.Color.White;
            Appearance1.OddRow.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            //选中行
            Appearance1.FocusedRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(211)))), ((int)(((byte)(128)))));
            Appearance1.FocusedRow.ForeColor = System.Drawing.Color.Black;

            //分组panel颜色
            Appearance1.GroupPanel.BackColor = System.Drawing.Color.White;
            Appearance1.GroupPanel.BackColor2 = System.Drawing.Color.CornflowerBlue;
            //分组row颜色
            Appearance1.GroupRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(198)))), ((int)(((byte)(232)))), ((int)(((byte)(243))))); // System.Drawing.Color.White;
            Appearance1.GroupRow.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(198)))), ((int)(((byte)(232)))), ((int)(((byte)(243)))));
            //空白区域颜色
            Appearance1.Empty.BackColor = System.Drawing.Color.LightYellow;
            //列标题颜色
            Appearance1.HeaderPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(229)))), ((int)(((byte)(249)))));

            //奇数行
            gridView1.Appearance.EvenRow.BackColor = Appearance1.EvenRow.BackColor;
            gridView1.Appearance.EvenRow.Font = Appearance1.EvenRow.Font;
            //偶数行
            gridView1.Appearance.OddRow.BackColor = Appearance1.OddRow.BackColor;
            gridView1.Appearance.OddRow.Font = Appearance1.OddRow.Font;
            //选中行
            gridView1.Appearance.FocusedRow.BackColor = Appearance1.FocusedRow.BackColor;   //选中的行
            gridView1.Appearance.FocusedCell.BackColor = Appearance1.FocusedRow.BackColor;  //选中的单元格
            gridView1.Appearance.FocusedRow.ForeColor = Appearance1.FocusedRow.ForeColor;   //字体颜色
            //分组panel颜色
            gridView1.Appearance.GroupPanel.BackColor = Appearance1.GroupPanel.BackColor;
            gridView1.Appearance.GroupPanel.BackColor2 = Appearance1.GroupPanel.BackColor2;
            //分组row颜色
            gridView1.Appearance.GroupRow.BackColor = Appearance1.GroupRow.BackColor;
            //  gridView1.Appearance.GroupRow.BackColor2 = Appearance1.GroupRow.BackColor2;
            //空白区域颜色
            gridView1.Appearance.Empty.BackColor = Appearance1.Empty.BackColor;
            //列标题颜色
            gridView1.Appearance.HeaderPanel.BackColor = Appearance1.HeaderPanel.BackColor;
        }

        void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; //行标题样式设置为居中对齐
            if (e.RowHandle==DevExpress.XtraGrid.GridControl.AutoFilterRowHandle)
            {
                e.Info.DisplayText = "筛选行";
            }
            if (e.Info.IsRowIndicator && e.RowHandle>=0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();  //写行号
            }
        }

        public void InitGroup(int groupIndex)
        {
            gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, "分组1");  //添加分组1,如果不是count,则名称必须与字段名对应
            gridView1.GroupFormat = "{1} {2}";  //默认"{0}: [#image]{1} {2}"; 字段名称:数据 计数=?
            gridView1.Columns[groupIndex].GroupIndex = 0;  //设置默认分组列

           // gridView1.Columns["部门名称"].GroupIndex = groupIndex;  //设置默认分组列

            ////分组列格式
            //gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Average, "id", gridView1.Columns["id"]);
            //gridView1.GroupSummary[1].DisplayFormat = "AVG={0:c}";

            //gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, "姓名", gridView1.Columns["姓名"]);
            //((DevExpress.XtraGrid.GridSummaryItem)gridView1.GroupSummary[gridView1.GroupSummary.Count - 1]).DisplayFormat = "小计:{0:N0}";

            gridView1.ExpandAllGroups();

        }

    }

}

2、调用类

项目必须引用以下类库

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using Bestway.Windows.Tools;
using System.Data.SqlClient;

namespace gridView
{
    public partial class Form1 : Form
    {
        //public GridViewDev gridViewDev=new GridViewDev();

        public Form1()
        {
            InitializeComponent();
            gridControlEx1.InitView();

        }

        private void Form1_Load(object sender, EventArgs e)
        {            //汉化,此处注意要使用汉化项目属性必须是.net fremawork4,不能是.net fremawork profile
            DevExpress.XtraEditors.Controls.Localizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraEditorsLocalizationCHS();
            DevExpress.XtraGrid.Localization.GridLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraGridLocalizationCHS();

          #region LoadData
            DataTable tb = createTable(3,3);
            //DataTable tb =SQLcreate();
            gridControlEx1.DataSource = tb;
          #endregion

            gridControlEx1.InitGroup(0);

        }

         public DataTable SQLcreate()
        {
            string cmdtxt = "SELECT * FROM v_Personnel";
            SqlConnection cn = new SqlConnection("server=.;database=mydb;Uid=sa;Pwd=123");
            SqlDataAdapter dap = new SqlDataAdapter(cmdtxt, cn);
            DataSet ds = new DataSet();
            dap.Fill(ds, "table");
            return ds.Tables[0];
        }

         #region createTable
         private DataTable createTable(int colCount, int rowCount)
         {
             DataTable table = new DataTable();
             table.TableName = "示例表";

             for (int i = 0; i < colCount; i++)
             {
                 DataColumn col = new DataColumn();
                 col.Caption = "列" + i.ToString();
                 col.ColumnName = "列" + i.ToString();
                 table.Columns.Add(col);
             }

             List<string[]> lst = new List<string[]>() {
                                new string[]{"1", "1", "1" },
                                new string[]{"2", "2", "2" },
                                new string[]{"2", "2", "2" },
                                new string[]{"2", "2", "2" },
                                new string[]{"3", "3", "3" }};
             foreach (var item in lst)
             {
                  //DataRow row = table.NewRow();
                  table.Rows.Add(item);
             }
             /*
             for (int j = 0; j < rowCount; j++)
             {
                 DataRow row = table.NewRow();
                 for (int i = 0; i < colCount; i++)
                 {
                     row[i] = "行" + j.ToString();
                    //row[i] = "行" + j.ToString() + ",列" + i.ToString();
                 }
                 table.Rows.Add(row);
             }
            */
             return table;
         }
         #endregion

    }
}
时间: 2024-10-16 17:02:53

GridControl 二次封装,自定义颜色样式风格的相关文章

sass学习笔记(二):sass的不同样式风格的输出方法

sass的不同样式风格的输出方法 1.嵌套式nested Sass 提供了一种嵌套显示 CSS 文件的方式.例如 nav {   ul {     margin: 0;     padding: 0;     list-style: none;   }   li { display: inline-block; }   a {     display: block;     padding: 6px 12px;     text-decoration: none;   } } 在编译的时候带上参

arcgis api for js共享干货系列之二自定义Navigation控件样式风格

arcgis api for js默认的Navigation控件样式风格如下图: 这样的风格不能说不好,各有各的爱好,审美观,这里也不是重点,这里的重点是如何自定义一套自己喜欢的样式风格呢:自己自定义一个NavigationControl控件类,最终实现的效果如下图: 思路如下:其实就是在网上参照天地图或者谷歌地图的Navigation风格样式,下载它们的图片模版,然后自己创建div来实现图片的缩放平移.全图.左右上下平移等等地图导航功能: Navigation图片目录如下: 调用函数: //显

二次封装dojo slider

上次的二次封装timeslider,挺有意思,又来封装一个dojo的,样式还是用arcgis的.实现更多功能,包括HorizontalSlider和VerticalSlider, 刻度的显示隐藏,标签的显示和隐藏,上刻度和下刻度的显示隐藏,无序数显示刻度,标签图标的自由选择,大小选择....更多功能大家看完code也可以自己慢慢加进去哈~~~ code有点长,先上slider的class::MyCustomSlider.js [javascript] view plain copy /** * 

二次封装arcgis的timeslider

arcgis的timeslider是对dojo slider二次封装,项目需要,所有Map用统一样式的slider,所以写了一个common的dojo class,统一调用生成slider,作为对timeslider再次封装,感觉挺好用. 这个slider不一定要在Map里使用,还可以在其他地方调用.只是要包含arcgis的js包, 先上JavaScript class的code: [javascript] view plain copy /** * yilei create for IES  

对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)

首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览器,沿用原来的FLASH运行时,兼容IE6+,iOS 6+, android 4+.两套运行时,同样的调用方式,可供

IOS键盘样式风格有关设置

一.键盘风格 UIKit框架支持8种风格键盘. typedef  enum  { UIKeyboardTypeDefault,                 // 默认键盘:支持所有字符 UIKeyboardTypeASCIICapable,            // 支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation,   // 标准电话键盘,支持+*#等符号 UIKeyboardTypeURL,                     // 

键盘样式风格有关设置-iOS开发

一.键盘风格 UIKit框架支持8种风格键盘. typedef  enum  { UIKeyboardTypeDefault,                 // 默认键盘:支持所有字符 UIKeyboardTypeASCIICapable,            // 支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation,   // 标准电话键盘,支持+*#等符号 UIKeyboardTypeURL,                     // 

键盘样式风格有关设置

键盘的相关设置(UITextfield) 键盘样式风格有关设置: 原文章: 一.键盘风格 UIKit框架支持8种风格键盘. typedef enum { UIKeyboardTypeDefault, // 默认键盘:支持所有字符 UIKeyboardTypeASCIICapable, // 支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation, // 标准电话键盘,支持+*#等符号 UIKeyboardTypeURL, // URL键盘,有.com按钮

数据分页模块系列 (二) 完美封装PageModel实现分页模块

先说一下框架分页技术,在我们之前那个高校项目中使用DWZ实现的分页用了自定义标签使用起来也比较方便,除了DWZ很多框架已经给我们做好了分页我们需要做的仅仅是把一些分页参数传给我们的框架,俗话说你用别人的东西就得按着别人的来,得按着别人的框架进行布局了.传参了等等,这样灵活性大大降低,况且感觉使用框架频繁的一些软件一般是一些管理类型的,对界面的美观方便需求并不是很高,工整.能用就可以,然而呢,还有些界面需要灵活配置分页按钮.分页条等,这就需要把类似于这样的功能封装起来. 分页的模块很多人都在写都在