2

I want to update my data in the DataGridView (loaded from XML)

  private void dgv_AgendaAfspraken_MouseDoubleClick(object sender, MouseEventArgs e)
    {
       DataGridViewRow dr = dgv_AgendaAfspraken.SelectedRows[0];
       dtp_Date.Text = dr.Cells[0].Value.ToString();
       cbx_begeleider.Text = dr.Cells[1].Value.ToString();
       tbx_opleider.Text = dr.Cells[2].Value.ToString();
       tbx_bedrijf.Text = dr.Cells[3].Value.ToString();
       tbx_periode.Text = dr.Cells[4].Value.ToString();
    }

How do I update these results from the TextBoxes (when I'm changing it) from the same record I just picked them?

4

2 回答 2

1

首先初始化一个变量来保存你的行索引:

int selectedRow;

并将其分配给您选择的行:

selectedRow = dgv_AgendaAfspraken.SelectedRows[0].Index;

然后你可以通过SetValues方法传递参数来重置它们:

dgv_AgendaAfspraken.Rows[selectedRow].SetValues(dtp_Date.Text, cbx_begeleider.Text,  tbx_opleider.Text, tbx_bedrijf.Text, tbx_periode.Text);
于 2013-06-03T16:12:27.350 回答
1

从文本框更新..

dr.Cells[0].Value = convert.toint32(dtp_Date.Text);
dr.Cells[1].Value = convert.toint32(cbx_begeleider.Text);
dr.Cells[2].Value = convert.toint32(tbx_opleider.Text);
dr.Cells[3].Value = convert.toint32(tbx_bedrijf.Text);
dr.Cells[4].Value = convert.toint32(tbx_periode.Text);
于 2013-06-03T16:04:32.427 回答