我选中DataGrilView中某条数据,需要对此条纪录数据进行修改,怎么把所需要修改的各项数据填充到窗体的各个控件中?
请问各位这样怎么操作?谢谢!!

解决方案 »

  1.   


            private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.RowIndex >= 0)
                {
                    txt_UserID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                    txt_UserName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                    txt_Salary.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                    cbx_duty.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                }
            }
      

  2.   

     private void btn_update_Click(object sender, EventArgs e)
            {
                btn_update.Checked = false;
                if (dgv_ygda.SelectedCells.Count == 0)
                {
                    MessageBox.Show("请选择要修改的数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    string YGName = dgv_ygda.SelectedCells[2].Value.ToString();
                    Updateygdafrm updateygdafrm = new Updateygdafrm();
                    updateygdafrm.curr_xm = YGName;
                    updateygdafrm.curr_ygh = dgv_ygda.SelectedCells[1].Value.ToString();
                    updateygdafrm.ShowDialog();
                }
            }private void Updateygdafrm_Load(object sender, EventArgs e)
            {
                dboperate.BindDropdownjclist("tb_jclist", cb_ldgx, "劳动关系", 11);
                dboperate.BindDropdownjclist("tb_jclist", cb_zzmm, "政治面貌", 11);
                dboperate.BindDropdownjclist("tb_jclist", cb_zw, "职务", 11);
                dboperate.BindDropdownjclist("tb_jclist", cb_hyzk, "婚姻状况", 11);
                this.Text = "[" + curr_xm + "]的个人信息";
                string strSql = "select * from tb_dalist";
                DataSet ds = dboperate.GetTable(strSql);
                ds.Dispose();
                txt_ygh.Text = ds.Tables[0].Rows[0][2].ToString();
                txt_xm.Text = ds.Tables[0].Rows[0][4].ToString();
                txt_sfzh.Text = ds.Tables[0].Rows[0][8].ToString();
                txt_xb.Text = ds.Tables[0].Rows[0][5].ToString();
                txt_nl.Text=ds.Tables[0].Rows[0][6].ToString();
                txt_csrq.Text = ds.Tables[0].Rows[0][7].ToString();
                cb_zw.SelectedItem = ds.Tables[0].Rows[0][11].ToString();
                cb_ldgx.SelectedItem = ds.Tables[0].Rows[0][10].ToString();
                cb_zzmm.SelectedItem = ds.Tables[0].Rows[0][9].ToString();
                cb_hyzk.SelectedItem = ds.Tables[0].Rows[0][12].ToString();
                txt_ssbm.Text = ds.Tables[0].Rows[0][3].ToString();
                txt_tel.Text=ds.Tables[0].Rows[0][13].ToString();
                txt_mob.Text=ds.Tables[0].Rows[0][14].ToString();
                txt_hjdz.Text=ds.Tables[0].Rows[0][15].ToString();
                txt_jtdz.Text=ds.Tables[0].Rows[0][16].ToString();
                dtp_rzrq.Text=ds.Tables[0].Rows[0][17].ToString();
                txt_bz.Text=ds.Tables[0].Rows[0][25].ToString();
            }这是我目前写的代码,怎么和你写的联系起来啊
      

  3.   

    你值都获得了。
    在写个update语句不就好了
      

  4.   


                      try
        
                     {
                        
                        txtHouseNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
                        cboTypeName.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
                        txtPrice.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
                        txtGuestNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
                        txtBedNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
                        cboState.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
                        txtDescription.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
                    }
                    catch
                    {
                    } 
      

  5.   


     //当点击 dataGridView1 时在文本框显示相应的信息
            private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (select == 0)
                {
                    try
                    {
                        txtHouseNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
                        cboTypeName.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
                        txtPrice.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
                        txtGuestNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
                        txtBedNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
                        cboState.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
                        txtDescription.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
                    }
                    catch
                    {
                    } 
                }
                if (select == 1)
                {
                    try
                    {
                        txtHouseNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][0].ToString();
                        cboTypeName.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
                        txtPrice.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
                        txtGuestNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
                        txtBedNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
                        cboState.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
                        txtDescription.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][6].ToString();
                    }
                    catch 
                    {
                    }
                }
            }
      

  6.   

    用BindingSource
    MyBindingSource.DataSource = dt;
    DataGridView.DataSoure =MyBindingSource;
    textBox2.DataBindings.Add("Text", MyBindingSource, ".字段A");
    ...
      

  7.   

    在SelectedIndexChanged事件里.直接这样取值就可以了.GV.SelectedRow.Cells[0].Text.ToString();
    GV.SelectedRow.Cells[1].Text.ToString();直接赋给你的文本就可以了.
      

  8.   

    用BindingSource做中转是一个比较简单的手段,不用写太多同步代码,他自己会保持同步更新滴
      

  9.   

    原来是这句话的问题:string strSql = "select * from tb_dalist";