一、常用控件样式

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)()))), ((int)(((byte)()))), ((int)(((byte)()))));
Appearance1.EvenRow.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
//偶数行
Appearance1.OddRow.BackColor = System.Drawing.Color.White;
Appearance1.OddRow.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
//选中行
Appearance1.FocusedRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
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)()))), ((int)(((byte)()))), ((int)(((byte)()))));
Appearance1.GroupRow.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
//空白区域颜色
Appearance1.Empty.BackColor = System.Drawing.Color.LightYellow;
//列标题颜色
Appearance1.HeaderPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
//奇数行
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; //字体颜色
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 = ; //设置默认分组列
}

二、设置分组显示格式

gridView1.GroupFormat = "{0}: [#image]{1} {2}"; //"字段名:图标 字段值";
gridView1.GroupFormat = "{1} {2}"; //"字段值";

三、统计汇总字段

       gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, "分组1");  //添加分组1,如果不是count,则名称必须与字段名对应
gridView1.GroupFormat = "{1} {2}"; //默认"{0}: [#image]{1} {2}"; 字段名称:数据 计数=?
gridView1.Columns["FieldName1"].GroupIndex = ; //设置默认分组列 //分组列格式
gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Average, "id", gridView1.Columns["id"]);
gridView1.GroupSummary[].DisplayFormat = "AVG={0:c}"; gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, "姓名", gridView1.Columns["姓名"]);
((DevExpress.XtraGrid.GridSummaryItem)gridView1.GroupSummary[gridView1.GroupSummary.Count - ]).DisplayFormat = "小计:{0:N0}";
//展开
gridView1.ExpandAllGroups();

四、对列的操作

        //设某一列只读或者不可编辑
gridView1.Columns[].OptionsColumn.AllowEdit = false;
gridView1.Columns[].OptionsColumn.ReadOnly = false; //设某一列文字和标题局中显示
gridView1.Columns[].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
gridView1.Columns[].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; //去掉某一列上面的自动筛选功能(Filter)
gridView1.Columns[].OptionsFilter.AllowAutoFilter = false;
gridView1.Columns[].OptionsFilter.AllowFilter = false;
gridView1.Columns[].OptionsFilter.ImmediateUpdateAutoFilter = false; //设置冻结列(左冻结)
gridView1.Columns[].Fixed= DevExpress.XtraGrid.Columns.FixedStyle.Left; //得到单元格数据(0行0列)
string ss = gridView1.GetRowCellDisplayText(, gridView1.Columns[]);
string ss = gridView1.GetRowCellValue(, gridView1.Columns[]);
//设置单元格数据(将0行0列的单元格赋值123)
gridView1.SetRowCellValue(, gridView1.Columns[], ""); //手动添加dev的列
DevExpress.XtraGrid.Columns.GridColumn Col1 = new DevExpress.XtraGrid.Columns.GridColumn();
Col1.FieldName="FID";
Col1.Visible=true;
Col1.VisibleIndex=gridView1.Columns.Count;
gridView1.Columns.Add(Col1);

五、一些常用事件

//设置自动增加的行号,需要先添加给gridview添加事件CustomDrawRowIndicator
private void gridview_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= )
e.Info.DisplayText = (e.RowHandle + ).ToString();
} //删除: (修改了dgvdel里的datagridviewdel方法)
public static void datagridviewdel_Dev(DevExpress.XtraGrid.Views.Grid.GridView Mydgv)
{
if (MessageBox.Show("你确定要删除选中的记录吗?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, , false) == DialogResult.Yes)
{
int iSelectRowCount = Mydgv.SelectedRowsCount;
if (iSelectRowCount > )
{
Mydgv.DeleteSelectedRows();
}
}
}
//新增:
private void btn_add_Click(object sender, EventArgs e)
{
gridView1.AddNewRow();
}
//新增行初始值设置:
private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
{
ColumnView View = sender as ColumnView;
View.SetRowCellValue(e.RowHandle, View.Columns[], gridView1.GetRowCellValue(gridView1.GetRowHandle(gridView1.RowCount - ), gridView1.Columns[])); //复制最后一行的数据到新行
View.SetRowCellValue(e.RowHandle, View.Columns[], gridView1.GetRowCellValue(gridView1.GetRowHandle(gridView1.RowCount - ), gridView1.Columns[])); //复制最后一行的数据到新行
}
//保存 datagridviewsave

六、获取行高

GridViewInfo vi = gridView1.GetViewInfo() as GridViewInfo;
GridRowInfo ri = vi.RowsInfo.FindRow();
int height = ;
if (ri != null)
height = ri.Bounds.Height;

DevExpress GridControl 控件点滴的更多相关文章

  1. DevExpress GridControl控件行内新增、编辑、删除添加选择框

    以下为内容以图片居多1234表示点击顺序 先新增一行 操作和新增数据行一样 打开ColumnEdit  选择new ButtenEdit  new上方会出现一个系统命名的button 命名可以更改必须 ...

  2. DevExpress GridControl控件行内新增、编辑、删除添加选择框(转)

    http://blog.csdn.net/m1654399928/article/details/21951519 1.首先到GridControl控件设计里设置属性Repository    (In ...

  3. 设置DevExpress GridControl控件时间列显示时、分、秒样式

    如题,如果Dev GridControl控件绑定DataTable数据源时,DataTable中的某一列为Date类型时,GridControl默认显示样式只显示当前日期,并不会将时.分.秒显示出来. ...

  4. DevExpress gridControl控件动态绑定列 zt

    DataTable dt = =Query.GetCustome=(ref customColumnCount); //绑定列 gridView.Columns.Add(}); gridView.Co ...

  5. DevExpress GridControl 控件二表连动

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. DevExpress控件的GridControl控件小结

    DevExpress控件的GridControl控件小结 (由于开始使用DevExpress控件了,所以要点滴的记录一下) 1.DevExpress控件组中的GridControl控件不能使横向滚动条 ...

  7. DevExpress之GridControl控件小知识

    DevExpress之GridControl控件小知识 一.当代码中的DataTable中有建数据关系时,DevExpress 的 GridControl 会自动增加一个子视图 .列名也就是子表的字段 ...

  8. DevExpress的GridControl控件更新數據問題解決辦法

    開發WPF程序時,使用Devexpress的GridControl控件用ItemSource綁定數據,在頁面進行編輯時,當屬性繼承INotifyPropertyChanged接口時會同步更新後臺數據. ...

  9. 【转】Devexpress使用之:GridControl控件(合并表头)

    Devexpress系列控件功能很强大,使用起来也不太容易,我也是边摸索边使用,如果有时间我会把常用控件的使用方法整理出来的. using System; using System.Collectio ...

随机推荐

  1. PAT (Basic Level) Practise (中文)- 1015. 德才论 (25)

    http://www.patest.cn/contests/pat-b-practise/1015 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡 ...

  2. 简单的邮件发送mail.jar

    public class MailSender { final static Logger logger = Logger.getLogger(MailSender.class); /** * 发送简 ...

  3. c++作业:使用函数调用的方法,实现求两个整数中大的数的程序。

    #include <iostream> using namespace std; int main(){ //从键盘接收两个整数,保存在变量num1和num2中 cout<<& ...

  4. QQ 发送邮件

    之前也发布过一篇QQ发邮件的,后来那种方法在阿里云服务器中报错了,查了好久才发现,是阿里云的服务器把 25 端口 给封杀了.现在重新做了个功能. public static string UserNa ...

  5. javascript设计模式(张容铭)学习笔记 - 外观模式绑定事件

    有一个需求要为document对象绑定click事件来是想隐藏提示框的交互功能,于是小白写了如下代码: document.onclick = function(e) { e.preventDefaul ...

  6. kmp和hash 字符串处理 哈希表

    来自http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html 并进行自己的简单整 ...

  7. 【android】签署应用采用相同证书的用处

    在应用的预期生命周期内,您应使用相同证书签署所有 APK 应用升级:当系统安装应用的更新时,它会比较新版本和现有版本中的证书.如果证书匹配,则系统允许更新.如果您使用不同的证书签署新版本,则必须为应用 ...

  8. thinkphp5中php7中运行会出现No input file specified. 这个你改个东西

    <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{RE ...

  9. How to setup multimedia on CentOS 7

    You will need to also install the EPEL repository as nux-dextop depends on this for some of its pack ...

  10. Spring boot 中Spring data JPA的应用(一)

    最近一直在研究Spring Boot,今天为大家介绍下Spring Data JPA在Spring Boot中的应用,如有错误,欢迎大家指正. 先解释下什么是JPA JPA就是一个基于O/R映射的标准 ...