Row update from Datagridview by textboxes
10,657
Solution 1
First initialize a variable to save your row index:
int selectedRow;
and assign it your selected row:
selectedRow = dgv_AgendaAfspraken.SelectedRows[0].Index;
Then you can just pass the parameters through SetValues
method to reset them:
dgv_AgendaAfspraken.Rows[selectedRow].SetValues(dtp_Date.Text, cbx_begeleider.Text, tbx_opleider.Text, tbx_bedrijf.Text, tbx_periode.Text);
Solution 2
Update from the textboxes ..
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);
Author by
Bert Bakker
Updated on June 04, 2022Comments
-
Bert Bakker almost 2 years
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?