In my Windows Forms Application, basically I have two DataGridViews. I want to select rows from right one and add selected rows to the left.
The right DataGridViewhas a checkbox column.
See the image :

For example :
-
Click the first row and Click Add button.
-
Click the third row and Click Add button.
The problem is the first row was added twice because it was ticked.
How can I make sure that rows added are distinct?
My Code:
foreach (DataGridViewRow row in dgRight.Rows)
{
DataGridViewCheckBoxCell check = row.Cells[0] as DataGridViewCheckBoxCell;
if (check.Value != null)
{
if ((bool)check.Value)
{
DataRow myRow = (row.DataBoundItem as DataRowView).Row;
DataRow dr = dt.NewRow();
dr[0] = myRow[0];
dr[1] = myRow[1];
dr[2] = myRow[2];
dr[3] = myRow[3];
dt.Rows.Add(dr);
}
}
}
dgLeft.DataSource = dt;
Check if the row already exists in the
Data Tableby using the.Findmethod: