1如何给devexpress的gridview控件绘制全选按钮
1 首先注册gridview的this.edibandedGridView.CustomDrawColumnHeader += EdibandedGridView_CustomDrawColumnHeader事件,然后在事件中写入如下代码:
private void EdibandedGridView_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
RepositoryItemCheckEdit checkItem = new RepositoryItemCheckEdit();
GridView _view = sender as GridView;
_view.DrawHeaderCheckBox(checkItem, "Check", e);
}
其中DrawHeaderCheckBox方法为其扩展方法:
public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs 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, getCheckedCount2(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();
}
然后注册 this.edibandedGridView.MouseDown += EdibandedGridView_MouseDown事件实现全选和单选:
private void EdibandedGridView_MouseDown(object sender, MouseEventArgs e)
{
GridView _view = sender as GridView;
_view.SyncCheckStatus("Check", e);
}
SyncCheckStatus方法为扩张方法。DrawHeaderCheckBoxExtension类为所有所需方法的封装类
public static class DrawHeaderCheckBoxExtension
{
public static void SyncCheckStatus(this GridView view, string fieldeName, MouseEventArgs e)
{
if (e.Clicks == 1 && e.Button == MouseButtons.Left)
{
view.ClearSorting();
view.PostEditor();
GridHitInfo _info;
Point _pt = view.GridControl.PointToClient(Control.MousePosition);
_info = view.CalcHitInfo(_pt);
if (_info.InColumn && _info.Column.FieldName.Equals(fieldeName))
{
if (getCheckedCount(view, fieldeName) == view.DataRowCount)
UnChekAll(view, fieldeName);
else
CheckAll(view, fieldeName);
}
}
}
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 ((bool)_cellValue)
if (_checkStatus)
count++;
}
}
return count;
}
private static void CheckAll(GridView view, string fieldName)
{
for (int i = 0; i < view.DataRowCount; i++)
{
var row = view.GetRow(i) as GIDManager.Utility.GIDAPIDataServiceAPI.EDISearchEntity;
if (row!=null)
{
row.Check = true;
}
}
view.RefreshData();
}
private static void UnChekAll(GridView view, string fieldName)
{
for (int i = 0; i < view.DataRowCount; i++)
{
var row = view.GetRow(i) as GIDManager.Utility.GIDAPIDataServiceAPI.EDISearchEntity;
if (row != null)
{
row.Check = false;
}
//view.SetRowCellValue(i, col, false);
}
view.RefreshData();
}
public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs 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, getCheckedCount2(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 getCheckedCount2(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;
}
}
1如何给devexpress的gridview控件绘制全选按钮的更多相关文章
- Android开发CheckBox控件,全选,反选,取消全选
在Android开发中我们经常会使用CheckBox控件,那么怎么实现CheckBox控件的全选,反选呢 首先布局我们的界面: <?xml version="1.0" enc ...
- devexpress中gridview控件编辑时改变输入法状态
在win7环境下使用Devexpress中的SpinEdit控件,切换成中文[简/繁]输入法输入数字键时有不少输入法会重复产生数字如输入1会变成11,输入123会变成112233.使用SpinEdit ...
- 【转】使用DevExpress的WebChartControl控件绘制图表(柱状图、折线图、饼图)
第一次写博,没什么经验,主要是把最近自己对Dev的一些研究贴出来大家共同探讨,有不足之处望大家帮忙斧正. WebChartControl是DevExpress控件群下的一个Web图表控件,它使用非常的 ...
- Winform中使用DevExpress的CheckEdit控件实现多选条件搜索
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- Android 实现自己定义多级树控件和全选与反选的效果
博文開始之前,首先要感谢大牛:(lmj623565791),本博文是在其博文http://blog.csdn.net/lmj623565791/article/details/40212367基础上进 ...
- 控件_CheckBox(多选按钮)
import android.os.Bundle; import android.app.Activity; import android.widget.CheckBox; import androi ...
- ASP.NET CheckBoxList 控件实现全选、反选、清除功能 利用js
直接看代码: JS代码如下: <script type="text/javascript" language="javascript"> funct ...
- 027. asp.net中数据绑定控件之 GridView控件
GridView控件支持下面的功能: 绑定至数据源控件, 如SqlDataSource 内置排序功能 内置更新和删除功能 内置分页功能 内置行选择功能 可以编程方式访问GridView对象模型以动态设 ...
- Winform 中DataGridView、dev Gridview控件添加行标题
有很多种方法. 1.可以在DataGridView控件中的RowStateChanged事件改变行标题单元格的值(Row.HeaderCell.Value) /// <summary> / ...
随机推荐
- LC 740. Delete and Earn
Given an array nums of integers, you can perform operations on the array. In each operation, you pic ...
- easyUI之Dialog(对话框窗口)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- Selenium 2自动化测试实战40(单线程)
单线程 #onethread.py #coding:utf-8 from time import sleep,ctime #听音乐任务 def music(): print('i was listen ...
- openstack部署neutron
controller 1.创建数据库并设置权限 mysql -u root -p0330 CREATE DATABASE neutron; GRANT ALL PRIVILEGES ON neutro ...
- AES 加密算法的原理详解
AES 加密算法的原理详解 本教程摘选自 https://blog.csdn.net/qq_28205153/article/details/55798628 的原理部分. AES简介 高级加密标准( ...
- HTMLCollection对象和NodeList对象
前言 首先我们先来看下面的demo,假如我们需要给所有的li字体变一个颜色. <!DOCTYPE html> <html lang="en"> <he ...
- jupyterlab部署到docker
操作环境:mac OS 10.14.6 docker版本:10.03.1 终端:iterm2 3.3 时间:2019年8月 ::说明::jupyter没有提供单独的jupyterlab镜像,可以使用j ...
- OOP理念
面向过程让计算机有步骤地顺次做一件事情,是一种过程化地叙事思维.但是在大型软件开发过程中,发现用面向过程语言开发,软件维护.软件复用存在着巨大困难,代码开发变成了记流水账,久而久之就称为"面 ...
- 支付宝网站即时支付开发,MD5加签名规则处理代码展示
一.如果传入进来的Object对象,最后生成制定格式的字符换 text: list拼接成字符串,map中的所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,list的元素之间用“| ...
- vim中ctrl+z,jobs,fg命令用法
例如:vi test.cctrl + z 将vi 打开的test.c停止并转到后台又打开一个vi buf.cctrl + z 将vi 打开的buf.c停止并转到后台此时通过jobs可以看到任务列表通过 ...