Primer Scot

Primer Scot

  • NA
  • 14
  • 606

Transfer selected rows in dgv1 of Form1 to dgv2 of Form2 many times

Sep 9 2022 6:57 AM

Hello everyone on this platform;

I realy want to transfer selected rows from dataGridView1 of Form1 to dataGridView2 of Form2. I'm able to select rows and transfer them for the first time but the case is that I'm failing to select other rows in dataGridView1 of Form1 and add them under the previously added rows in dataGridView2 of Form2. 

I tried the following codes and areexecuted after clicking a button to transfer selectd rows.

private void btn_PassDta_Click(object sender, EventArgs e)
{
    List<CommonValue> CV = new List<CommonValue>();
    foreach (DataGridViewRow item in dataGridView1.Rows)
    {
        if (Convert.ToBoolean(item.Cells[0].Value))
        {
            CV.Add(new CommonValue
            {
                Colum1 = item.Cells[1].Value.ToString(),
                Colum2 = item.Cells[2].Value.ToString(),
                Column3 = item.Cells[3].Value.ToString()

            });
        }
    }

    Result_Form frm = new Result_Form();
    frm.Values = CV;
    frm.Show();
}

// The CommonValue in the above codes is a class created for set; and get

I need to come and reselect other row in dataGridView1 of Form1, click the buton then find the selected row(s) under the prevously transferred row (in Blue color) in dataGridView2 of Form2 to have many as selected from dataGridView1.

I will appreciate everyone's help.

Regards!


Answers (2)