I have 2 DataGridView namely dgvEmpEnrollees and dgvEmpMustAttend which have a DataTable as data sources namely dtEnrollees and dtMustAttend respectively.
I have a btnRemove which removes the currently selected row in the dgvEmpEnrollees datagridview dtEnrollees DataTable and immediately updates the Datagridview and I want this same row to be added in the second DT and DGV.
Note: The 2 DataTables are cloned:
btnRemove code snippet is as follows:
private void btnRemove_Click(object sender, EventArgs e)
{
DataRowView currentDataRowView = (DataRowView)dgvEmpEnrollees.CurrentRow.DataBoundItem;
DataRow row = currentDataRowView.Row;
dtEnrollees.Rows.Remove(row);
dgvEmpEnrollees.DataSource = null;
dgvEmpEnrollees.DataSource = dtEnrollees;
dtMustAttend.Rows.InsertAt(row,0);
dgvEmpMustAttend.DataSource = null;
dgvEmpMustAttend.Rows.Clear();
dgvEmpMustAttend.DataSource = dtMustAttend;
}
This row belongs to another table error in C# prompts afterwards.
I have also tried the dtMustAttend.ImportRow(row); method, it doesn't prompt an error but the row won't add.
Any help would be much appreciated.