DataGridView列中添加CheckBox
来源:互联网 发布:算法导论电子版 编辑:程序博客网 时间:2024/05/01 08:09
今天工作中遇到需要在DataGridView手动添加CheckBox;根据数据的不同添加的列也不同,除去用户列其他全部添加CheckBox,我还是第一次做个功能,在帮助中找到了相关信息,开始试验遇到一个错误:错误如下:
DataGridView中发生一下异常:System.FormatException:单元格的Formatted值的类型错误.要替换此默认对话框,请处理DataError时间.
点击以后有一对话框错误如下:
DataGridView中发生一下异常:
SystemArgumentException:为DataGridViewCheckBoxCell提供的值的类型错误.
在System.Windows.Forms.DataGridViewCheckBoxCell.set_EditiingCellFormattedValue(Object value)
在System.Windows.Forms.DataGridView.InitializeEditingCellValue(DataGridViewCessStyle&dataGridViewCellStyle,DataGridViewCell&dataGridViewCell)
要替换此默认对话框,请处理DataError事件.
这两个错误找了好久才知道 错在那里 现在分析一下;下面是原帮助代码
private void AddOutOfOfficeColumn(){ DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); { column.HeaderText = ColumnName.OutOfOffice.ToString(); column.Name = ColumnName.OutOfOffice.ToString(); column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; column.FlatStyle = FlatStyle.Standard; column.ThreeState = true; column.CellTemplate = new DataGridViewCheckBoxCell(); column.CellTemplate.Style.BackColor = Color.Beige; } DataGridView1.Columns.Insert(0, column);}
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.datagridviewcheckboxcolumn(VS.80).aspx这个是DataGridViewCheckBoxColumns类的地址:
请注意红色字地方;如果按照原来的这样就报错;把这两句修改成
column.ThreeState = true;
column.CellTemplate = new DataGridViewCheckBoxCell(true);
或者
column.ThreeState = false;
column.CellTemplate = new DataGridViewCheckBoxCell(false);
就可以了.这就可以放心用了.!!!!!
- DataGridView列中添加CheckBox
- Winform中 DataGridView添加 CheckBox列的问题集锦
- 在datagridview中添加列
- DataGridView 代码中添加列
- DataGridView 列中添加进度条
- gridControl1 中添加checkbox 列
- DataGridView中添加CheckBox控件主…
- DataGridView列头checkbox
- 在 DatagridView 中加图像列和 Checkbox 列
- DataGridView 添加checkBox
- DataGridView 添加checkbox
- DataGridView 添加checkbox
- DataGridView 添加checkbox
- DataGridView 添加checkbox
- DataGridView如何添加CheckBox?
- DataGridView中CheckBox列运行时候System.FormatException异常
- DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- c#DataGridView控件中CheckBox列的使用
- 支持免费的办公软件 IBM Symphony
- ORACLE 数据库备份----------------rman
- JSP多文件上传
- 说说:国外的开源程序
- org.gjt.mm.mysql.Driver与com.mysql.jdbc.Driver的区别
- DataGridView列中添加CheckBox
- db2数据库之三:SQL语言
- PHP函数图片的处理
- 数据挖掘概念综述
- RUP的十大要素
- OpenOffice
- 一篇让你javascript提升的文章
- 两表关联进行更新,使用T2的数据更新T1(等值更新)
- 仿Windows文件搜索 JAVA 实现