I have a form with a datagrid
that has a list of records from the table. When the user selects one record to edit its value I want to return to the same row (record) in the datagrid and display it as selected. Of course the datagrid should show the new(edited) values.
The code in the EditButton
does all of it, but the result is not what expected.
private void zButtonEdit1_Click(object sender, EventArgs e)
{
// Store the rowIndex and columnIndex values
zButtonEdit1.rowIndex = dataGridView1.CurrentRow.Index;
zButtonEdit1.cellIndex = dataGridView1.CurrentCell.ColumnIndex;
// Store the Id of the current record
zButtonEdit1._id_ = Convert.ToInt16( dataGridView1["id_lice", zButtonEdit1.rowIndex].Value.ToString());
// Open the Editform with required data for that ID
Lice frmLice = new Lice(zButtonEdit1.UIB, zButtonEdit1._id_);
frmLice.ShowDialog();
// When editing is finished, refresh the grid with new values
refresh_controls();
//Set the current record pointer (or row pointer) to the record that was edited
this.dataGridView1.Rows[zButtonEdit1.rowIndex].Cells[zButtonEdit1.cellIndex].Selected = true;
}
This is what I get Datagrid on Form
Its obvious that I changed only the selection but I have no idea how to change row
(record) pointer.