DataGridView添加DataGridViewCheckBoxColumn

sparrow429 2009-04-20 08:29:14
DataGridView是工具栏里面拉出来的,DataGridViewCheckBoxColumn也是直接在界面上添加上去的,行是程序里面添加的,但是单击DataGridViewCheckBoxColumn,
在cellclick里面写代码,有时候能点击上,有时候不能,特别是点击快的时候,要点两次才行
代码如下,
初始化时候Column1.DefaultCellStyle.NullValue = true;//设置初始值
点击
private void answerParameterDGV_CellClick(object sender, DataGridViewCellEventArgs e)
{
answerParameterDGV.CommitEdit(DataGridViewDataErrorContexts.Commit);
if (e.ColumnIndex == 0)
{
if ((((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag) == null ||
(((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag.ToString()) == "0")
{
((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag = "1";
((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Value = true;
}
else if((((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag.ToString()) == "1")
{
((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag = "0";
((DataGridViewCheckBoxCell)answerParameterDGV.Rows[e.RowIndex].Cells[e.ColumnIndex]).Value = false;
}
}
}
...全文
305 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sparrow429 2009-04-21
  • 打赏
  • 举报
回复
...readonly设成false或者true都不行啊
wxm3630478 2009-04-21
  • 打赏
  • 举报
回复
哦 搞错了是 DataGridViewCheckBoxColumn 就有CheckBox 那列

wxm3630478 2009-04-21
  • 打赏
  • 举报
回复
把DataGridViewTextBoxColumn列 设置为不可编辑 Enabled = false 就OK 了
feifeiyiwen 2009-04-21
  • 打赏
  • 举报
回复
支持4楼
LoveLife_Go 2009-04-21
  • 打赏
  • 举报
回复
你的这列readonly没设成false就可以添文本
sparrow429 2009-04-21
  • 打赏
  • 举报
回复
怎么在DataGridViewTextBoxColumn的列里面写文本呢??
sparrow429 2009-04-21
  • 打赏
  • 举报
回复
谢谢,写错事件了..
sparrow429 2009-04-21
  • 打赏
  • 举报
回复
是我自己弄错了,又绑定了一个datatable,去掉这句就好了
wuyq11 2009-04-20
  • 打赏
  • 举报
回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧