I am trying to update individual record in SQL table. So, I have DataGridView view of that table, and when some row is selected in table and Update button is clicked, new Update Form is opened.
Main Form passes DataRow row parameter to new Form, and when update is over, row is returned to Main Form. Code example is about like this in Main Form:
private void btnUpdateUser_Click(object sender, EventArgs e)
{
//Some code to extract DataRow
FormUpdateUsers updateUser = new FormUpdateUsers(row, new Action<DataRow>(onUserUpdated));
updateUser.Show();
}
When Update Form finishes update, it invokes action and returns row to Main Form, as shown below.
public partial class FormUpdateUsers : Form
{
private DataRow row;
private Action<DataRow> action;
public FormUpdateUsers(DataRow row, Action<DataRow> action)
{
InitializeComponent();
this.row = row;
this.action = action;
}
private void btnConfirm_Click(object sender, EventArgs e)
{
//Some code for updatin a database
action.Invoke(row);
}
}
Question is, how to insert returned row bask to DataGridView and replace the outdated one? Any suggestions?
private void onUserUpdated(DataRow row)
{
// Update DataGridView?
}
You have to know which row. Do you have any id column already inside dgv (and datarow)?
If so, then you can do: