DataGridView 中第一列"chk"为
DataGridViewCheckBoxColumn如何在初始化的时候让"chk"列 为默认选中打勾的状态 if (dgvProperties.Rows[i].Cells["chk"].Value  == null)
                    {
                        dgvProperties.Rows[i].Cells["chk"].Value  =  true ;
                    } 这样是不可以的而DataGridViewCheckBoxColumn1.checked 这样的属性又不存在

解决方案 »

  1.   

    dgvProperties.Rows[i].Cells["chk"].FindControl("CheckBoxName").Value = true;
      

  2.   

    循环遍历dgvProperties.Rows,然后判断Cells["chk"]这列的Control的类型(gettype)是不是CheckBox,之后实例化CheckBox ch = (CheckBox)dgvProperties.Rows[i].Cells["chk"],这样你可以判断 ch是不是被选中了。。
      

  3.   

    类型转换之后的Cell---转换成了CheckBox 有checked属性!
      

  4.   

    for (int j = 0; j <= this.Controls.Count - 1; j++)
                {
                    string ControlName = this.Controls[j].GetType().ToString();
                    if ("CheckBox".Equals(ControlName))
                    {
                        
                CheckBox ch = CheckBox ch = (CheckBox)Controls[j];                    if (ch.Name = "ch" + j.ToString())//ch1,ch2,ch3....
                        {
                            if (ch.Checked == true)//被选中的
                            {                        }
                        }
                    }
                }给你个小例子,参考下
      

  5.   

    可以这样来写:
    dataGridView1.Rows.Add(true);
    如果要定位到某行的话这样写
    需要先实例化
    DataGridViewCheckBoxCell dc3 ;
    dc3 = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[7];
    dc3.Value = true;
    不明白可以到我的blog
    http://hi.baidu.com/iaskall
      

  6.   

    设置那一列的默认值为true.
    ColumnCheckBox.DefaultCellStyle.NullValue = true;
      

  7.   

    void DataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
            {
                try
                {
                    DataGridView curDgv = (DataGridView)sender;
                    for (int i = 0; i < curDgv.Rows.Count; i++)
                    {
                        curDgv.Rows[i].Cells["chk"].Value = true;
                    }
                }
                catch
                {
                }
            }
    在dgv 绑定完成后,做判断
    谢谢各位,马上揭帖