日期:2014-05-19  浏览次数:20868 次

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;