设置一个DataGridView,通过DataAdapter连接数据库后,将数据库中的数据,显示在DataGridView中,单击行中的数据,同时将行中的数据逐个显示在我在窗体下方所设的TextBox文本框中,现在我要设置一个Button完成修改操作,需要通过修改TextBox中的值来完成,并将值传递至数据库完成对数据库中的数据修改,如何操作?
  本人刚接触C#,恳请各位高手指教,谢过啦~!

解决方案 »

  1.   

    哈哈,试出来了,dgvMain.SelectedRows[0].Cells[0].Value = txtStuNo.Text;
    请问还有别的什么更好的方法吗?
    可以调用DateRow方法吗。。
      

  2.   

    dgvStudents.AutoGenerateColumns = false
    解决了,少了上面一句代码
    另外数据库的表要设个主键,还是自己动手丰衣足食嘿嘿
      

  3.   

    这就是关于选中datagridview某一行的问题呢
    小菜,下面是关于如何选中datagridview的代码
    if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex >= 0)
                    {
                        try
                        {
                            dataGridView1.ClearSelection();
                            dataGridView1.Rows[e.RowIndex].Selected = true;
                            dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                            contextMenuStrip1.Show(MousePosition.X,MousePosition.Y);
                        }
                        catch (ArgumentException)
                        {
                            MessageBox.Show("出错了");
                        }
                    }
                }
    选中之后就可以直接修改了啊,如下
    if ((dataGridView1.CurrentRow.Cells[0].Value) != null)
                  txt_mc.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
      

  4.   

    示例图如下
    http://hi.csdn.net/space-6131721-do-album-picid-768283-goto-up.html
      

  5.   

    对我有用,最近也是在头大DataGridView的问题,大家一起努力加油喽!
      

  6.   

    this.dgv1.rows[e.rowIndex]["列名"].value 得到即将修改的值this.dgv1.rows[e.rowIndex]["标识列"].value  找到标识列,提供给where 子条件语句