下面是我的代码,在这个事件中检测状态,我的checkbox列是设计时加入的,运行时这面下的代码没有问题,但是只能慢慢的点,速度一快了,比如双击一下,旁边的审核栏不变化了,而这个状态栏却变了。应该怎么解决这个问题,到底是怎么回事啊。先谢谢大家了。  
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
            if (e.ColumnIndex == 0)
            {
                if (((DataGridViewCheckBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag == null)
                {
                    ((DataGridViewCheckBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag = "1";
                    this.dataGridView1.Rows[e.RowIndex].Cells[8].Value = "已审核";
                }
                else if (Convert.ToBoolean(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == true)
                {
                    ((DataGridViewCheckBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag = "0";
                    this.dataGridView1.Rows[e.RowIndex].Cells[8].Value = "";
                }
                else
                {
                    ((DataGridViewCheckBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]).Tag = "1";
                    this.dataGridView1.Rows[e.RowIndex].Cells[8].Value = "已审核";
                }
            }
                
        }

解决方案 »

  1.   

    那个是审核栏,那个是状态栏,把gridview的格式贴出来看一下.
      

  2.   

    很简单的,普通表格,只有第8列的右边是checkbox列
      

  3.   

     没完全理解什么意思,你不是是要在用户双击的时候要保持checkbox之前的状态? Checkbox是状态栏?
      

  4.   

     private string SeletedID()
        {        CheckBox chkExport;
            string StrSql = string.Empty;
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                chkExport = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
                if (chkExport.Checked == true)
                {
                    StrSql += "" + ((Label)GridView1.Rows[i].FindControl("lbId")).Text.Trim() + ",";
                }
            }
    }
    返回的是  checked 行 的 主键值 组成的 字符串 
      

  5.   

    我不是说非要通过哪种方式,只要这一列的某一单元格的状态改变了,如从“勾选状态”到“不勾选状态”,就要执行判断后的代码。如下面我改后的代码:
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)  
            {
                this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
                 if (e.ColumnIndex == 8)
                 {
                     if (this.dataGridView1.Rows[e.RowIndex].Cells[8].FormattedValue.ToString() == "True")
                     {
                         this.dataGridView1.Rows[e.RowIndex].Cells[7].Value = "已审核";
                     }
                     else
                     {
                         this.dataGridView1.Rows[e.RowIndex].Cells[7].Value = "";
                     }
                 }
            }
    现在的问题是该事件是“单击单元格”的事件,只要是单击就没事,如果双击或乱击,就不对了,有时虽然勾选状态变了,但是没执行代码。如果用按空格键的方式代替单击动作,就没问题,严格按照逻辑判断来执行。请问,怎么能够真正依靠该单元格的状态值来执行。
      

  6.   

    DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)row.Cells[];
                    if (cell.Value != null)
                    {
                        if ((bool)cell.Value == true)
                        {
                            你的动作
                        }
                    }
      

  7.   

    再加一个CellContentDoubleClick事件
    把CellContentClick事件中的代码copy一份就可以了