当复选框被选中时,那一行的第二个单元格进入编辑状态?这个怎么实现,各位大虾们帮帮忙!

解决方案 »

  1.   


    private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
            {
                if (e.ColumnIndex == 1)
                {
                    dataGridView1.Rows[e.RowIndex].Cells[0].Value = true;
                }
            }
      

  2.   

    写在 CellClicked 中:    if(e.ColumnIndex==0 && (bool)datagridview1[0,e.Rowindex].Value==true)
        {
             datagridview1[1,e.RowIndex].Selected=true;
             datagridview1.BeginEdit(true);
        }
        
      

  3.   

    dgv好像没有这个CellClicked 事件吧
    只有个CellClick事件。
    但是这个事件显然是不行的。
    当鼠标刚单击时就触发了这个事件,就不能得到这个复选框真实的值了。
      

  4.   


            private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.RowIndex == -1) return;             
                if (e.ColumnIndex == 0)
                {
                    dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
                    if (dataGridView1[0, e.RowIndex].Value == null) return;
                    if ((bool)dataGridView1[0, e.RowIndex].Value == true)
                    {
                        dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[1];
                        dataGridView1.BeginEdit(true);
                    }                 
                }
            }
    试下这个,开始没有看清楚问题,不好意思呀
      

  5.   

    谢谢这位老兄。
    dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    但是你能解释一下这句话的意思吗?
    是不是提前把单元格的值提前提交到数据缓存中。
      

  6.   

    MSDN上的解释是:
      将当前单元格中的更改提交到数据缓存,但不结束编辑模式。
    跟你想的差不多,不调用这个的方法的话,那要等移出来单元格才能提交了