我想在 我点击ADD按钮是,光标 移动到  最后一行,即新行。能的 话,在设置焦点在新行  行首。也就相当于添加了新行。感谢大家!!

解决方案 »

  1.   

    使用BindingSource进行绑定比如
    this.dataGridView.DataSource=this.bindingSource1;
    this.bindingSource1.DataSource=ds.Table[0];//ds.Table[0]是你要绑定的表使用BindingSource.MoveLast()方法可以将焦点移到最后一行。
      

  2.   

    更新使用DataAdapter的Update方法。
      

  3.   

    补充一下,要调用adapter对象的update方法有两个要点
    1. 先执行:SqlCommandBuilder b = new SqlCommandBuilder(adapter对象名);
    再调用adapter对象名.Update()2. 确保adapter的selectcommand里面的sql语句中包含一个主键列,否则无法更新的
      

  4.   


    dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[0];
    dataGridView1.BeginEdit(true);
      

  5.   

    dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Count-1;
      

  6.   

    定位cell。dataGridView1.FirstDisplayedCell = dataGridView1.Rows[xxx].Cells[0];
      

  7.   


    还是CurrentCell 好用。
      

  8.   

    dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1RowCount-1].Cells[列索引];
    dataGridView1.BeginEdit(true);
      

  9.   

    如果是用BindingSource绑定的话可以直接用BindingSource.MoveLast()来定位的
      

  10.   

    2楼的方法我没用过,应该能好用。11楼类似。3楼的方法不能用,我试了,提示说,数据绑定后不能用Add方法。4楼,可行,复杂一点点~~~5楼,应该好用,没用。
    感谢你们,希望成为朋友,共同讨论问题,共同进步,谢谢大家》》
      

  11.   

         
       private void tlsMnuItemAdd_Click(object sender, EventArgs e)
            {
                iXgbz = 1; //增加数据
                dgvDrugs.AllowUserToAddRows = true; //允许用户添加新的数据
                setDgvAllowEdit(dgvDrugs);
                setMenuItemEnabled(false, false, false, false, false, true);//设置菜单项状态
                dgvDrugs.CurrentCell = dgvDrugs.Rows[dgvDrugs.Rows.Count - 1].Cells[0];
                dgvDrugs.BeginEdit(true);
            }