devexpress 多个c checkedit dbnull怎么设置智能选择一个

2017年6月 总版技术专家分月排行榜第三
2017年9月 .NET技术大版内专家分月排行榜第一2017年8月 多媒体开发大版内专家分月排行榜第一2017年8月 .NET技术大版内专家分月排行榜第一2017年7月 多媒体开发大版内专家分月排行榜第一2017年7月 .NET技术大版内专家分月排行榜第一2017年6月 .NET技术大版内专家分月排行榜第一2017年5月 多媒体开发大版内专家分月排行榜第一2017年4月 多媒体开发大版内专家分月排行榜第一2016年1月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年11月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年10月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年9月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年7月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年6月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年3月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年2月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年1月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年12月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年11月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年10月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年9月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年8月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年7月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一
2017年6月 总版技术专家分月排行榜第三
2017年9月 .NET技术大版内专家分月排行榜第一2017年8月 多媒体开发大版内专家分月排行榜第一2017年8月 .NET技术大版内专家分月排行榜第一2017年7月 多媒体开发大版内专家分月排行榜第一2017年7月 .NET技术大版内专家分月排行榜第一2017年6月 .NET技术大版内专家分月排行榜第一2017年5月 多媒体开发大版内专家分月排行榜第一2017年4月 多媒体开发大版内专家分月排行榜第一2016年1月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年11月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年10月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年9月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年7月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年6月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年3月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年2月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2015年1月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年12月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年11月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年10月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年9月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年8月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一2014年7月 多媒体/设计/Flash/Silverlight 开发大版内专家分月排行榜第一
本帖子已过去太久远了,不再提供回复功能。Posts - 83,
Articles - 2,
Comments - 15
摸着石头过河……
01:14 by kelite, ... 阅读,
到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能。在寻找答案的过程的成果进行记录。
一、13.2版本以后用法
启用多选列对Gird中的View进行以下属性设置:
gridView1.OptionsSelection.MultiSelect =
gridView1.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowS
清除当前选择在选中列时后,可配置在选中列以外的地方点击时候会清除当前的选择。14以后才有此功能gridView1.OptionsSelection.ResetSelectionClickOutsideCheckboxSelector =
获取选中的行
二、早起版本实现
& & &相关链接:/Support/Center/Example/Details/E1271
GridCheckMarksSelection类
1 public class GridCheckMarksSelection {
protected GridView _
protected ArrayL
RepositoryItemCheckE
const int CheckboxIndent = 4;
public GridCheckMarksSelection()
selection = new ArrayList();
public GridCheckMarksSelection(GridView view) : this() {
public GridView View {
get { return _ }
if (_view != value) {
Attach(value);
public GridColumn CheckMarkColumn { get { return } }
public int SelectedCount { get { return selection.C } }
public object GetSelectedRow(int index) {
return selection[index];
public int GetSelectedIndex(object row) {
return selection.IndexOf(row);
public void ClearSelection() {
selection.Clear();
Invalidate();
public void SelectAll() {
selection.Clear();
// fast (won't work if the grid is filtered)
//if(_view.DataSource is ICollection)
selection.AddRange(((ICollection)_view.DataSource));
for (int i = 0; i & _view.DataRowC i++)
selection.Add(_view.GetRow(i));
Invalidate();
public void SelectGroup(int rowHandle, bool select) {
if (IsGroupRowSelected(rowHandle) && select) return;
for (int i = 0; i & _view.GetChildRowCount(rowHandle); i++) {
int childRowHandle = _view.GetChildRowHandle(rowHandle, i);
if (_view.IsGroupRow(childRowHandle))
SelectGroup(childRowHandle, select);
SelectRow(childRowHandle, select, false);
Invalidate();
public void SelectRow(int rowHandle, bool select) {
SelectRow(rowHandle, select, true);
public void InvertRowSelection(int rowHandle) {
if (View.IsDataRow(rowHandle)) {
SelectRow(rowHandle, !IsRowSelected(rowHandle));
if (View.IsGroupRow(rowHandle)) {
SelectGroup(rowHandle, !IsGroupRowSelected(rowHandle));
public bool IsGroupRowSelected(int rowHandle) {
for (int i = 0; i & _view.GetChildRowCount(rowHandle); i++) {
int row = _view.GetChildRowHandle(rowHandle, i);
if (_view.IsGroupRow(row)) {
if (!IsGroupRowSelected(row)) return false;
if (!IsRowSelected(row)) return false;
return true;
public bool IsRowSelected(int rowHandle) {
if (_view.IsGroupRow(rowHandle))
return IsGroupRowSelected(rowHandle);
object row = _view.GetRow(rowHandle);
return GetSelectedIndex(row) != -1;
protected virtual void Attach(GridView view) {
if (view == null) return;
selection.Clear();
this._view =
view.BeginUpdate();
edit = view.GridControl.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckE
column = view.Columns.Add();
column.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.F
column.Visible = true;
column.VisibleIndex = 0;
column.FieldName = "CheckMarkSelection";
column.Caption = "Mark";
column.OptionsColumn.ShowCaption = false;
column.OptionsColumn.AllowEdit = false;
column.OptionsColumn.AllowSize = false;
column.UnboundType = DevExpress.Data.UnboundColumnType.B
column.Width = GetCheckBoxWidth();
column.ColumnEdit =
view.Click += new EventHandler(View_Click);
view.CustomDrawColumnHeader += new ColumnHeaderCustomDrawEventHandler(View_CustomDrawColumnHeader);
view.CustomDrawGroupRow += new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
view.CustomUnboundColumnData += new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
view.KeyDown += new KeyEventHandler(view_KeyDown);
view.RowStyle += new RowStyleEventHandler(view_RowStyle);
} finally {
view.EndUpdate();
protected virtual void Detach() {
if (_view == null) return;
if (column != null)
column.Dispose();
if (edit != null) {
_view.GridControl.RepositoryItems.Remove(edit);
edit.Dispose();
_view.Click -= new EventHandler(View_Click);
_view.CustomDrawColumnHeader -= new ColumnHeaderCustomDrawEventHandler(View_CustomDrawColumnHeader);
_view.CustomDrawGroupRow -= new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
_view.CustomUnboundColumnData -= new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
_view.KeyDown -= new KeyEventHandler(view_KeyDown);
_view.RowStyle -= new RowStyleEventHandler(view_RowStyle);
_view = null;
protected int GetCheckBoxWidth() {
DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo info = edit.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewI
int width = 0;
GraphicsInfo.Default.AddGraphics(null);
width = info.CalcBestFit(GraphicsInfo.Default.Graphics).W
} finally {
GraphicsInfo.Default.ReleaseGraphics();
return width + CheckboxIndent * 2;
protected void DrawCheckBox(Graphics g, Rectangle r, bool Checked) {
DevExpress.XtraEditors.ViewInfo.CheckEditViewI
DevExpress.XtraEditors.Drawing.CheckEditP
DevExpress.XtraEditors.Drawing.ControlGraphicsInfoA
info = edit.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewI
painter = edit.CreatePainter() as DevExpress.XtraEditors.Drawing.CheckEditP
info.EditValue = C
info.Bounds =
info.CalcViewInfo(g);
args = new DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs(info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
painter.Draw(args);
args.Cache.Dispose();
void Invalidate() {
_view.CloseEditor();
_view.BeginUpdate();
_view.EndUpdate();
void SelectRow(int rowHandle, bool select, bool invalidate) {
if (IsRowSelected(rowHandle) == select) return;
object row = _view.GetRow(rowHandle);
if (select)
selection.Add(row);
selection.Remove(row);
if (invalidate) {
Invalidate();
void view_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
if (e.Column == CheckMarkColumn) {
if (e.IsGetData)
e.Value = IsRowSelected(View.GetRowHandle(e.ListSourceRowIndex));
SelectRow(View.GetRowHandle(e.ListSourceRowIndex), (bool)e.Value);
void view_KeyDown(object sender, KeyEventArgs e) {
if (View.FocusedColumn != column || e.KeyCode != Keys.Space) return;
InvertRowSelection(View.FocusedRowHandle);
void View_Click(object sender, EventArgs e) {
Point pt = _view.GridControl.PointToClient(Control.MousePosition);
info = _view.CalcHitInfo(pt);
if (info.Column == column) {
if (info.InColumn) {
if (SelectedCount == _view.DataRowCount)
ClearSelection();
SelectAll();
if (info.InRowCell) {
InvertRowSelection(info.RowHandle);
if (info.InRow && _view.IsGroupRow(info.RowHandle) && info.HitTest != GridHitTest.RowGroupButton) {
InvertRowSelection(info.RowHandle);
void View_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) {
if (e.Column == column) {
e.Info.InnerElements.Clear();
e.Painter.);
DrawCheckBox(e.Graphics, e.Bounds, SelectedCount == _view.DataRowCount);
e.Handled = true;
void View_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e) {
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowI
info = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowI
info.GroupText = "
" + info.GroupText.TrimStart();
e.Info.Paint.FillRectangle(e.Graphics, e.Appearance.GetBackBrush(e.Cache), e.Bounds);
e.Painter.);
Rectangle r = info.ButtonB
r.Offset(r.Width + CheckboxIndent * 2 - 1, 0);
DrawCheckBox(e.Graphics, r, IsGroupRowSelected(e.RowHandle));
e.Handled = true;
void view_RowStyle(object sender, RowStyleEventArgs e) {
if (IsRowSelected(e.RowHandle)) {
e.Appearance.BackColor = SystemColors.H
e.Appearance.ForeColor = SystemColors.HighlightT
GridCheckMarksSelection类
1 public Form1()
InitializeComponent();
new GridCheckMarksSelection(gridView1);1. RepositoryItemCheckEdit默认有三种状态,选中状态、未选中状态和半选中状态(半选中状态通常用在TreeList中如果父节点下 的子节点有选中的有未选中的,则父节点状态为半选中状态)。如果RepositoryItemCheckEdit所在的列未绑定数据源,那么该列默认只可 以单选;如果绑定了数据源,那么可以同时多选。
2. 问题描述:
&上述描述的ColumEdit关联FieldName数据源,但是在设计功能中并不仅仅这样就可以同时多选,还是选中后,在Grid其他的位置再单击鼠标,选中状态还是变为非选中。
在"是否需要协助"该类是一个复选框,那怎样才能实现多选的功能,选中之后不会点击其他地方又自动消失选中状态呢?3.解决方法
这时需要我们为这个字段关联一个事件,事件代码如下:
private void repositoryItemCheckEdit1_QueryCheckStateByValue(object sender, DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs e)
string val = "";
if (e.Value != null)
val = e.Value.ToString();
val = "False";//默认为不选
switch (val)
case "True":
case "Yes":
e.CheckState = CheckState.C
case "False":
case "No":
e.CheckState = CheckState.U
e.CheckState = CheckState.C
e.Handled = true;
接下来为这个复选框字段进行关联事件
this.repositoryItemCheckEdit1.QueryCheckStateByValue += new DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventHandler(this.repositoryItemCheckEdit1_QueryCheckStateByValue);
接下来运行程序RepositoryItemCheckEdit这个字段就可以实现多选的功能啦!
阅读(...) 评论()下次自动登录
现在的位置:
& 综合 & 正文
Devexpress中gridcontrol控件checkedit无法多选问题解决
调用Gridcontrol,列编辑器类型采用CheckEdit,选择结果无法保存,无法多选。
解决方案:该列绑定的数据类型一定要是布尔型,且要赋初值
代码如下:
DataTable pPersonTable=m_pPersonLogic.GetPersonInfo("");
DataColumn dtCol=new DataColumn();
dtCol.ColumnName = "bSel";
dtCol.DataType=System.Type.GetType("System.Boolean");
dtCol.DefaultValue=
pPersonTable.Columns.Add(dtCol);
&&&&推荐文章:
【上篇】【下篇】}

我要回帖

更多关于 dev checkedit用法 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信