[DevExpress]GridControl 列头绘制Checkbox
关键代码:
/// <summary> /// 为列头绘制CheckBox /// </summary> /// <param name="view">GridView</param> /// <param name="checkItem">RepositoryItemCheckEdit</param> /// <param name="fieldName">需要绘制Checkbox的列名</param> /// <param name="e">ColumnHeaderCustomDrawEventArgs</param> public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs e) { /*说明: *参考:https://www.devexpress.com/Support/Center/Question/Details/Q354489 *在CustomDrawColumnHeader中使用 *eg: * private void gvCabChDetail_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e) * { * GridView _view = sender as GridView; * _view.DrawHeaderCheckBox(CheckItem, "Check", e); * } */ if (e.Column != null && e.Column.FieldName.Equals(fieldName)) { e.Info.InnerElements.Clear(); e.Painter.DrawObject(e.Info); DrawCheckBox(checkItem, e.Graphics, e.Bounds, getCheckedCount(view, fieldName) == view.DataRowCount); e.Handled = true; } } private static void DrawCheckBox(RepositoryItemCheckEdit checkItem, Graphics g, Rectangle r, bool Checked) { CheckEditViewInfo _info; CheckEditPainter _painter; ControlGraphicsInfoArgs _args; _info = checkItem.CreateViewInfo() as CheckEditViewInfo; _painter = checkItem.CreatePainter() as CheckEditPainter; _info.EditValue = Checked; _info.Bounds = r; _info.PaintAppearance.ForeColor = Color.Black; _info.CalcViewInfo(g); _args = new ControlGraphicsInfoArgs(_info, new DevExpress.Utils.Drawing.GraphicsCache(g), r); _painter.Draw(_args); _args.Cache.Dispose(); } private static int getCheckedCount(GridView view, string filedName) { int count = 0; for (int i = 0; i < view.DataRowCount; i++) { object _cellValue = view.GetRowCellValue(i, view.Columns[filedName]); if (_cellValue == null) continue; if (string.IsNullOrEmpty(_cellValue.ToString().Trim())) continue; bool _checkStatus = false; if (bool.TryParse(_cellValue.ToString(), out _checkStatus)) { if (_checkStatus) count++; } } return count; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }代码使用:
RepositoryItemCheckEdit CheckItem = new RepositoryItemCheckEdit(); const string gcCheckFieldName = "Checked"; private void gvLampConfig_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) { GridView _view = sender as GridView; _view.DrawHeaderCheckBox(CheckItem, gcCheckFieldName, e); }
代码效果:
希望有所帮助!
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
[DevExpress]GridControl 列头绘制Checkbox的更多相关文章
- 实现在DevExpress.XtraGrid.GridControl的列头绘制复选框以实现全选的功能
首先新建一个Win Form测试项目,拖一个GridControl控件到窗体上. public partial class Form1 : Form { public Form1() { Initia ...
- DevExpress GridControl 列中显示图片
一.GridControl 的Columns中添加列 1.列名:FieldName命名为img 2.类型:ColumnEdit属性中 选择PictureEdit类型(RepositoryItemPic ...
- [DevExpress]GridControl 同步列头checkbox与列中checkbox状态
关键代码: /// <summary> /// 同步列头checkbox与列中checkbox状态 /// </summary> /// <param name=&quo ...
- dev gridControl 自定义绘制列头颜色
1.添加事件CustomDrawColumnHeader private void gvw1_CustomDrawColumnHeader(object sender, DevExpress.Xtra ...
- Winform DataGridView添加列头checkbox
using System; using System.Data; using System.Drawing; using System.Windows.Forms; using Yanwen.Logi ...
- gridcontrol的列头右键菜单问题
Dev控件GridControl设置了一个右键菜单 this.gridControl1.ContextMenu = contextMenu2; 而GridControl在运行排序的时候,即 gridv ...
- DevExpress中GridControl列转义的实现方法
/// <summary> /// CustomColumnDisplayText Helper /// </summary> /// <param name=" ...
- DevExpress GridControl功能总结
写在前面,Dev控件已经很久了,功能也很强大,截止到现在我编写文档出来的Dev的版本已经到了14.1了,看了Demo真的很强大,效果也很好,结合自己这一个月开发,分享一下自己研究过后的经验,不让大家走 ...
- DevExpress GridControl使用(转)
DevExpress GridControl使用 (一)原汁原味的表格展示 Dev控件中的表格控件GridControl控件非常强大.不过,一些细枝末节的地方有时候用起来不好找挺讨厌的.使用过程中,多 ...
随机推荐
- MySQL 5.7 新特性大全和未来展望 图解
本文转自微信公众号:高可用架构 作者:杨尚刚 引用 美图公司数据库高级 DBA,负责美图后端数据存储平台建设和架构设计.前新浪高级数据库工程师,负责新浪微博核心数据库架构改造优化,以及数据库相关的服务 ...
- vim中光标的前进和后退
流行的文本编辑器通常都有前进和后退功能,可以在文件中曾经浏览过的位置之间来回移动.在 vim 中使用 Ctrl-O 执行后退,使用 Ctrl-I 执行前进.相关帮助: :help CTRL-O :h ...
- c语言数组的初始化
#include "stdio.h" int main() { ][]; a[][]="1,2,3,4,5,6,7,8,9,10,11,12"; ]=a,*p= ...
- centos、linux改变ll命令显示颜色
服务器用的centOS,用putty管理时,在命令行下目录用蓝色显示,很难看清.可以用以下两种方法改变: 方法一: 1.直接修改个人帐户目录下的.color.rc文件. 找到 DIR 01;34,修改 ...
- Jfinal学习笔记
实习期间,公司使用jfinal做开发,所以就学习了这个框架 Jfinal作为一个极速ORM,使用上非常方便,核心源代码1万多行,压缩后只有200多KB. 从入口开始 作为一个web项目,首先解读web ...
- HDU 1978 How many ways (DP)
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 用Activator.CreateInstance代替new实现类的实例化(转)
一直想得到这样一个函数,输入一个类的名称为参数,返回一个相应的类的实例. 这在工厂模式中是非常有用的 这样,可以使程序有更高的扩展性,例如,,下面的例子 如果现在有一个类,专门用来计算交通工具的速度, ...
- li颜色特效
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- Table of Contents - JAXB
Getting Started Hello World Hello World with Namespace xjc - 将 XML Schema 编译成 Java 类 wsimport: 编译 WS ...
- DialogFragment
DialogFragment 从Android 3.0 (API level 11)开始引入,如果想在低于该版本的系统上使用,需用android.support.v4.app.DialogFragme ...