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);//画列头CheckEditgv.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 图例:

 

转载于:https://www.cnblogs.com/jzssuanfa/p/6795660.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416808.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

msfconsole 无法启动,解决办法

今天突然碰上kali msfconsole 无法启动&#xff0c;经过查找资料&#xff0c;现已成功解决该问题&#xff0c;现将解决办法整理如下&#xff1a; service postgresql start     # 启动数据库服务 msfdb init             # 初始化数据库 msfconsole     …

centos7 zookeeper3.5.6单机伪集群部署

接上篇文章centos7 zookeeper单点部署准备好zookeeper包&#xff0c;进行集群部署 单机伪集群部署 zookeeper1 zookeeper2 zookeeper3 三个目录分别部署一个服务。 cp -r apache-zookeeper-3.5.6-bin/ zookeeper1 cd zookeeper1/ mkdir data vi conf/zoo.cfg 修改 dataDir/op…

centos7 kafka2.3.1单机伪集群部署

接上篇文章centos7 zookeeper单点部署&#xff0c;准备好相应的包 cp config/server.properties config/server0.properties vi config/server0.properties 修改 broker.id0 listenersPLAINTEXT://192.168.81.145:9092 #注意&#xff0c;这里一定要有客户端可访问的ip&…

POJ_2513Colored Sticks 字典树+

比较考察技术含量的一道题。 参考链接:http://blog.csdn.net/lyy289065406/article/details/6647445 题目链接:http://poj.org/problem?id2513 首先差不多能想到这事欧拉路&#xff0c;然后发现没法构图。没有尝试使用map&#xff0c;刚好最近在学字典树就直接上了。 然后就是…

superset0.34源码级别汉化

下载源码 git clone https://github.com/apache/incubator-superset.git cd incubator-superset 切换到0.34版本 git checkout 0.34 进入js打包目录 cd superset/assets/ yarn install yarn build 打包后的文件在superset/assets/dist目录 yarn dev 进行cheap-module-eval-s…

humanize时间库使用及汉化

python3 zh_CN包需要到github下载https://github.com/jmoiron/humanize humanize/locale/zh_CN >>> import humanize >>> import datetime >>> humanize.naturaltime(datetime.timedelta(seconds3)) 3 seconds ago >>> humanize.i18n.ac…

socket编程介绍

Python 提供了两个基本的 socket 模块。 第一个是 Socket&#xff0c;它提供了标准的 BSD Sockets API。 第二个是 SocketServer&#xff0c; 它提供了服务器中心类&#xff0c;可以简化网络服务器的开发。 下面讲的是Socket模块功能 1、Socket 类型 套接字格式&#xff1a; so…

Superset单点登录调整源码

///修改config.py from flask_appbuilder.security.manager import AUTH_REMOTE_USER AUTH_TYPEAUTH_REMOTE_USER from custom_sso_security_manager import CustomSsoSecurityManager CUSTOM_SECURITY_MANAGER CustomSsoSecurityManager AUTH_USER_REGISTRATION True …

webpack-dev-server 搭建本地服务以及浏览器实时刷新

一、概述开发项目中为了保证上线&#xff0c;开发项目是都需要使用localhost进行开发&#xff0c;以前的做法就是本地搭建Apache或者Tomcat服务器。有的前端开发人员 对服务器的搭建和配置并不熟悉&#xff0c;这个时候需要后台开发人员进行帮忙&#xff0c;有的时候后台开发人…

java调用kafka

pom.xml <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.3.1</version> </dependency> 注意调试通过后要添加…

[Noi2015]软件包管理器

来自FallDream的博客&#xff0c;未经允许&#xff0c;请勿转载&#xff0c;谢谢。 Linux用户和OSX用户一定对软件包管理器不会陌生。通过软件包管理器&#xff0c;你可以通过一行命令安装某一个软件包&#xff0c;然后软件包管理器会帮助你从软件源下载软件包&#xff0c;同时…

ELK+Kafka部署

目录 1.背景 2.ELK的配置 2.1.下载 2.2.关闭防火墙 2.3.安装elasticsearch 2.4.安装Logstash 2.5.安装Kibana 2.6.Java日志输出到Logstash 2.7.OSS版本 3.Kafka的配置 3.1.zookeeper搭建 3.2.kafka搭建 4.整合 1.背景 高日志压力情况下&#xff0c;为了避免Logsta…

Allegro改动shape网络节点

使用Allegro时改动shape的网络节点方法&#xff1a; ①选择shape->Select Shape or Void/Cavity ②选择要改动的shape ③点击&#xff08;...&#xff09;改动网络节点的名字 ④改动完毕 转载于:https://www.cnblogs.com/claireyuancy/p/6804046.html

ELK套件FileBeat部署

目录 1.简介 2.下载 3.直接输出到ElasticSearch 4.输出到Logstash 5.更改nginx日志路径 6.logstash负载均衡 7.日志文件直接作为输入 1.简介 FileBeat用于文件数据采集并输出到ElasticSearch或Logstash中。 ELK搭建过程参见&#xff1a; ELK搭建及Java程序接入 2.下载…

python基础之数据类型

python基础之数据类型 字符串(string) 用引号括起的都是字符串,其中的引号可以是单引号, 也可以是双引号1.使用方法修改字符串的大小写 例&#xff1a; >>> name "ada lovelace" >>> print name.title() Ada Lovelace >>> print(name.up…

MetricBeat(win/linux)部署 系统CPU内存等资源情况监控

目录 1.下载 2.linux系统监控 ​3.启用模块 4.windows系统监控 1.下载 下载MetricBeat的linux和windows版本 https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-oss-7.2.1-linux-x86_64.tar.gz https://artifacts.elastic.co/downloads/beats/metricbea…

android CoordinatorLayout使用

一、CoordinatorLayout有什么作用 CoordinatorLayout作为“super-powered FrameLayout”基本实现两个功能&#xff1a; 1、作为顶层布局 2、调度协调子布局 CoordinatorLayout使用新的思路通过协调调度子布局的形式实现触摸影响布局的形式产生动画效果。CoordinatorLayout通过…