首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DataGridView 的有关问题

2012-01-08 
DataGridView 的问题 在线等DataGridView中第一列 chk 为DataGridViewCheckBoxColumn如何在初始化的时候

DataGridView 的问题 在线等
DataGridView   中第一列 "chk "为
DataGridViewCheckBoxColumn

如何在初始化的时候让 "chk "列   为默认选中打勾的状态

  if   (dgvProperties.Rows[i].Cells[ "chk "].Value     ==   null)
                                        {
                                                dgvProperties.Rows[i].Cells[ "chk "].Value     =     true   ;
                                        }  

这样是不可以的

而DataGridViewCheckBoxColumn1.checked   这样的属性又不存在

[解决办法]
dgvProperties.Rows[i].Cells[ "chk "].FindControl( "CheckBoxName ").Value = true;
[解决办法]
循环遍历dgvProperties.Rows,然后判断Cells[ "chk "]这列的Control的类型(gettype)是不是CheckBox,之后实例化CheckBox ch = (CheckBox)dgvProperties.Rows[i].Cells[ "chk "],这样你可以判断 ch是不是被选中了。。
[解决办法]
可以这样来写:
dataGridView1.Rows.Add(true);
如果要定位到某行的话这样写
需要先实例化
DataGridViewCheckBoxCell dc3 ;
dc3 = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[7];
dc3.Value = true;
不明白可以到我的blog
http://hi.baidu.com/iaskall
[解决办法]
同意楼上的
[解决办法]
设置那一列的默认值为true.
ColumnCheckBox.DefaultCellStyle.NullValue = true;

热点排行