Gridview 自定义外观

private void Form1_Load(object sender, EventArgs e)
        {
            //汉化,需要引用DevExpress.Localization.v11.2.dll
            DevExpress.XtraEditors.Controls.Localizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraEditorsLocalizationCHS();
            DevExpress.XtraGrid.Localization.GridLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraGridLocalizationCHS();

            #region LoadData
            DataTable tb2 = SQLcreate();
            gridControl1.DataSource = tb2;
            #endregion
            gridViewDev.setDgv(gridView1);

        }

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

        }
       public void setDgv(DevExpress.XtraGrid.Views.Grid.GridView gridView1)
        {
            gridView1.OptionsView.ShowColumnHeaders = true;       //显示列标题
            gridView1.OptionsView.ShowIndicator = false;          // 不显示行标题
            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.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();//禁止排序

            gridView1.PaintStyleName = "Flat";   //设置外观样式
            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)))));
            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;
            //设置分组
            gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, "分组1");  //添加分组1,如果不是count,则名称必须与字段名对应
            gridView1.GroupFormat = "{1} {2}";  //默认"{0}: [#image]{1} {2}"; 字段名称:数据 计数=?
            gridView1.Columns["部门名称"].GroupIndex = 0;  //设置默认分组列
        }
        public void RestoreLayoutFromXml(DevExpress.XtraGrid.Views.Grid.GridView gridView1, string filePath)
        {
            gridView1.Appearance.RestoreLayoutFromXml(filePath);    //加载样式
        }

        public void SaveLayoutToXml(DevExpress.XtraGrid.Views.Grid.GridView gridView1, string filePath)
        {
            gridView1.Appearance.SaveLayoutToXml(filePath);  //保存样式
        }

时间: 2024-11-08 20:24:16

Gridview 自定义外观的相关文章

gridview自定义分页 aspNetPager用法

这几天做gridview分页,自带的分页不好用.从网上搜刚开始搜了一个aspNetPager.dll,替换原来的一个dll,自己设置了一些,比如这个控件不显示中文,后来我改成中文的"上一页"."下一页"."首页""尾页",把ShowPageIndexBox设置为默认true,这样当前页也显示了,还能跳转. 还设置了 显示自定义区域,默认是不显示了,我改成left,然后再设置下自定义的html,结果就可以显示了,我显示的是 一共

Yii2 GridView自定义链接之重写 ActionColumn

最近刚开始用yii2,真是超棒的,但是也有许多不足的地方,今天要说的就是GridView链接问题. <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'id', 'username', 'email', ['class' => 'yii\gri

关于GridView自定义绑定过程的行状态e.Row.RowState一点解析

GridView相信这个控件大家已经家喻户晓,而且用的也非常多了,本文针对GridView的行状态进行一点浅析,高手请留步,就此打住! 现在我们看个例子,现在要使用gridview输出一张订单表,订单有个状态字段取值为:0(未完成交易)1(已完成交易),现在重点是,我们绑定数据到gridview,显然绑定输出时候只能输出0和1,那么怎么实现将0输出为未完成交易,而1输出为已完成交易呢.这里我们就需要用到gridview为我们准备的数据行绑定事件了,如下图所示,我们订阅该事件,在gridview属

GridView自定义分页样式(上一页,下一页,到第几页)

今天要为网站做一个文章列表,发现GridView的分页样式很难看,于是结合网上的例子,自己做了一个.不是很美观,不过还是很实用的,先看下效果吧,如图(1). 图(1)GridView分页效果 自定义GridView的分页样式,使用的是GridView的  <PagerTemplate>元素.我们先看这段分页代码. 1 <PagerTemplate> 2 <br /> 3 <asp:Label ID="lblPage" runat="s

gridView自定义做时间排版

公司有需求要做一个时间排版,原型如下 因为要用的gridView,以前就是它的排版很多,最看是想用一个checkbox搞定.后来证实功能能够达到,但是排版是乱的.还是老老实实多写点吧(直接上代码) 技术不好什么地方不对求指正 首先是主页: public class MyActivity extends Activity { /** * Called when the activity is first created. */ private HashSet<Integer> shou = ne

gridview自定义表头

gridview为我们提供了丰富的接口,用于满足自定义需求. 通常asp:gridview会根据绑定的列Columns自动生成表头,展现在前台元素. 序号 类别 有时候需要复杂一些的表头. 序号 类别 数学 物理 化学 此时需要实现RowCreated事件 RowCreated提供了两个参数,重写表头. protected void RowCreated(object sender, GridViewRowEventArgs e) if (e.Row.RowType == DataControl

GridView 自定义表头

//修改表头 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.Header: TableCellCollection tcHeader = e.Row.Cells; tcHeader.Clear(); //第一行表头 tcHeader.Add(new TableHeaderCell()); tc

Android下如何自定义ProgressBar的外观

在Android应用中经常会用的到一些进度条,这些进度条的样子千差万别,但是大多都是由ProgressBar来的.但是Android系统自带的进度条样式却不太好看,今天要做的就是自定义一个好看的ProgressBar. 我们先来看看Android自带的进度条的样子: 我们今天的目标,自定义 的进度条的样子: 不难发现差距还是挺大的,好了,废话不多说,进入正题: 我们首先还是从源码入手,我们可以打开ADT目录下的sdk\platforms\android-16\data\res\values文件夹

android自定义gridview,根据item自动适应高度

代码如下 package com.loopfire.meitaotao.view; import android.content.Context; import android.util.AttributeSet; import android.widget.GridView; /** * 自定义gridview * @author hai * */ public class MyGridView extends GridView { public MyGridView(Context cont