先选择datagridview中的某行的任意单元格,然后点击修改按钮,此单元格处于编辑状态,然后再点击此行的其他单元格,此行的这些单元格都能够编辑,但是其他行的单元格不能为编辑请问如何实现??请给出代码,谢谢!

解决方案 »

  1.   

    private int iRow = -1;
    dataGridView1.ReadOnly = false; 
    设置RowEnter事件
    private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
            {
                dataGridView1.ReadOnly = iRow != e.RowIndex;
            }
    点击修改按钮后
    iRow = this.dataGridView1.SelectedRows[0].Index;
      

  2.   

    1、添加成员变量:
     private int iRow=-1;
    2、设置dataGridView1的readonly属性为true;
    3.private void button1_Click(object sender, EventArgs e)
            {
                this.dataGridView1.ReadOnly = false;
                iRow = this.dataGridView1.CurrentRow.Index;
            }        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
            {
                if (iRow != this.dataGridView1.CurrentRow.Index)
                {
                    this.dataGridView1.ReadOnly = true;
                }
                else
                {
                    this.dataGridView1.ReadOnly = false;
                }        }