只有单列的 datagridview ,通过 textBox 向 datagridview 中添加数据,新添加的数据排在最后数据添加完后,如何把单元格焦点移到新加的数据上?

解决方案 »

  1.   

    直接定位在最后一行呗datagridview .Rows[i].Selected = true;
      

  2.   

    datagridview.Rows[datagridview.Rows.Count-1].Selected = true;
      

  3.   

    你把SelectionMode 设置为CellSelect
    把AutoUserToAddRows修改为False private void button1_Click(object sender, EventArgs e)
            {
               //添加按钮事件
                string[] strArray = {this .textBox1 .Text};
                this .dataGridView1.Rows .Add (strArray );
                int index = this.dataGridView1.Rows.Count;
                if (index >1)
                {
                    this.dataGridView1.Rows[index - 2].Cells[0].Selected = false;
                }
                this.dataGridView1.Rows[index -1].Cells [0].Selected= true;
            }
      

  4.   

                    dataGridView5.Rows[dataGridView5.Rows.Count-2].Cells[0].Selected = true;
    解决,谢谢大家。我这datagridview绑定了一个datatable,所以行数要:dataGridView5.Rows.Count-2