GridControl 选择列、复选框全选(上)
说明:
GirdControl 中添加一列,这一列不是写在数据库中的,而是代码中添加的。
图示:
底层类代码:
#region GridControl 全选
/// <summary>
/// 是否选中
/// </summary>
private static bool chkState = false;
//复选框列名称
private static string chkFileName = "";
//复选框列宽
private static int chkWidth = 30;
//GridView
public static DevExpress.XtraGrid.Views.Grid.GridView GView = null;
private DevExpress.XtraGrid.Views.Grid.GridView gView {
get {
if (GView == null)
{
GView = new DevExpress.XtraGrid.Views.Grid.GridView();
}
return GView;
}
set {
this.gView = value;
}
} public static void GridCheckEdit(DevExpress.XtraGrid.Views.Grid.GridView gv, string checkFileName, int checkWidth)
{
if (gv != null) {
chkFileName = checkFileName;
chkWidth = checkWidth;
GView = gv;
//不显示复选框的列标题
gv.Columns[chkFileName].OptionsColumn.ShowCaption = false; //复选框的形状 gv.Columns[chkFileName].ColumnEdit 实例是 repositoryItemCheckEdit1
//repositoryItemCheckEdit1.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Standard;
////复选框加载的状态 实心 空心 空心打勾
//repositoryItemCheckEdit1.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
//点击事件
gv.Click += new System.EventHandler(gv_Click);
//画列头CheckEdit
gv.CustomDrawColumnHeader += new DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventHandler(gv_CustomDrawColumnHeader);
gv.DataSourceChanged += new EventHandler(gv_DataSourceChanged);
}
} private static void gv_Click(object sender, EventArgs e)
{
if (ClickGridCheckBox(GView, chkFileName, chkState))
{
chkState = !chkState;
}
} private static void gv_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column != null && e.Column.FieldName ==chkFileName)
{
e.Info.InnerElements.Clear();
e.Painter.DrawObject(e.Info);
DrawCheckBox(e, chkState);
e.Handled = true;
}
} private static void gv_DataSourceChanged(object sender, EventArgs e)
{
DevExpress.XtraGrid.Columns.GridColumn column = GView.Columns.ColumnByFieldName(chkFileName);
if (column != null)
{
column.Width = chkWidth;
column.OptionsColumn.ShowCaption = false;
column.ColumnEdit = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
}
} private static void DrawCheckBox(DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e, bool chk)
{
DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repositoryCheck = e.Column.ColumnEdit as DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit;
if (repositoryCheck != null)
{
System.Drawing.Graphics g = e.Graphics;
System.Drawing.Rectangle r = e.Bounds; DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo info;
DevExpress.XtraEditors.Drawing.CheckEditPainter painter;
DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs args;
info = repositoryCheck.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo; painter = repositoryCheck.CreatePainter() as DevExpress.XtraEditors.Drawing.CheckEditPainter;
info.EditValue = chk;
info.Bounds = r;
info.CalcViewInfo(g);
args = new DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs(info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
painter.Draw(args);
args.Cache.Dispose();
}
} private static bool ClickGridCheckBox(DevExpress.XtraGrid.Views.Grid.GridView gridView, string fieldName, bool currentStatus)
{
bool result = false;
if (gridView != null)
{
//禁止排序
gridView.ClearSorting(); gridView.PostEditor();
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo info;
System.Drawing.Point pt = gridView.GridControl.PointToClient(Control.MousePosition);
info = gridView.CalcHitInfo(pt);
if (info.InColumn && info.Column != null && info.Column.FieldName == fieldName)
{
for (int i = 0; i < gridView.RowCount; i++)
{
gridView.SetRowCellValue(i, fieldName, !currentStatus);
}
return true;
}
}
return result;
} #endregion
前台调用:
注意:GridControl绑定前,手动增加一列,增加完成之后,在绑定。
//添加一列
dt.Columns.Add("chk", System.Type.GetType("System.Boolean"));
dt.Columns["chk"].DefaultValue = Boolean.FalseString; gridControl1.DataSource = dt; Functionjsj.GridCheckEdit(gv, "chk", 50);
chk 图例:
版权声明:本文为博主原创文章,未经博主允许不得转载。
GridControl 选择列、复选框全选(上)的更多相关文章
- FineReport——JS二次开发(复选框全选)
在进行查询结果选择的时候,我们经常会用到复选框控件,对于如何实现复选框全选,基本思路: 在复选框中的初始化事件中把控件加入到一个全局数组里,然后在全选复选框里对数组里的控件进行遍历赋值. 首先,定义两 ...
- 复选框全选、全不选和反选的效果实现VIEW:1592
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- checkbox复选框全选批量删除
多选框全选实现批量删除 html代码 <body> <form action="" method="post" name="Form ...
- jQuery 复选框全选/取消全选/反选
jQuery实现的复选框全选/取消全选/反选及获得选择的值. 完整代码: <!DOCTYPE html> <html> <head> <script type ...
- jQuery 前端复选框 全选 反选 下拉菜单联动
jQuery 页面中复选框全选.反选.下拉联动(级联) <!DOCTYPE html> <html lang="en"> <head> < ...
- jQuery 实现复选框全选、反选及获取选中的值
实现复选框全选,反选及获取选中的值: 代码如下: <!doctype html> <html lang="en"> <head> <met ...
- js 复选框 全选都选 如果某一个子复选框没选中 则全选按钮不选中
<!DOCTYPE HTML> <html> <head> <meta charset=UTF-8> <title>js 复选框 全选都选 ...
- JavaScript小例子:复选框全选
JavaScript小例子:复选框全选 这只是一个小例子,很简单,但是这个功能还是很常用的: 实现后效果如图: JavaScript代码: <script type="text/jav ...
- Jquery表格变色 复选框全选,反选
/*jquery静态表格变色*/ $(".tr2").mouseover(function(){ $(this).css("background"," ...
- html+css+js实现复选框全选与反选
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- posix和system v有什么区别/?
posix和system v有什么区别/?现在在应用时应用那一标准浮云484212 | 浏览 243 次 2014-11-06 10:362014-11-19 22:36 最佳答案们是有关信号量的两组 ...
- 虚拟机重复创建系统去除SID
我们安装完的操作系统都会有一个SID,为了简化安装,现在大部分人会选择GHOST克隆安装,经过克隆后的系统SID是相同的,有时需要重新获取SID 以前WIN2003有修改SID的工具NEWSID ...
- 移动js
http://blog.sina.com.cn/s/blog_6553196001015672.html http://blog.sina.com.cn/s/blog_6553196001014vjb ...
- cs ip 通过jmp转移命令间接赋值。无法直接对其赋值。
jmp 寄存器 命令 对IP间接赋值.
- mac终端命令简介
mac终端命令简介(适合刚刚入手mac的新人们) 1.取得root权限 意义相当与windows中的超级管理员权限,甚至还要超出.root权限可以修改系统中的任何文件,不过对普通用户的意义不大,了解即 ...
- 在Hadoop伪分布式模式下安装Hbase
安装环境:Hadoop 1.2.0, Java 1.7.0_21 1.下载/解压 在hbase官网上选择自己要下的hbase版本,我选择的是hbase-0.94.8. 下载后解压到/usr/local ...
- POJ_2566_Bound_Found_(尺取法+前缀和)
描述 http://poj.org/problem?id=2566 给出一个整数序列,并给出非负整数t,求数列中连续区间和的绝对值最接近k的区间左右端点以及这个区间和的绝对值. Bound Found ...
- WordPress Think Responsive Themes ‘upload_settings_image.php’任意文件上传漏洞
漏洞名称: WordPress Think Responsive Themes ‘upload_settings_image.php’任意文件上传漏洞 CNNVD编号: CNNVD-201311-06 ...
- 转自 Good morning 的几句精辟的话
1.志愿者招募 根据流量平衡方程来构图非常方便,而且简单易懂,以后可能成为做网络流的神法之一 简单记一下流量平衡方程构图法的步骤: a.列出需求不等式 b.通过设置松弛变量,将不等式变成等式 c.两两 ...
- [HDU POJ] 逆序数
HDU 1394 Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...