0

how to tranfer Form1 checked GridView Rows Data on Form2 Gridview?

Like This: enter image description here

Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69
user2491383
  • 160
  • 2
  • 4
  • 13
  • > Finally I did it with the help of this [Click Here](http://stackoverflow.com/questions/19627471/how-to-copy-transfer-values-from-form2-datagridview-to-form1-datagridview-in-c) – user2491383 Mar 13 '14 at 20:24

1 Answers1

1

There are lot of ways to achieve this. The simplest that comes in my mind is:

-Create an istance of GetDataForm and call a method which displays the form and get the result:

GetDataForm form2 = new GetDataForm();
List<DataGridViewRow> res = form2.ShowForm();
for (int i = 0; i < res.Count; i++)
    mainFormGrid.Rows.Add(res[i]);

-In your GetDataForm you should have the following method:

bool _closedByTransferButton = false;
public List<DataGridViewRow> ShowForm() 
{ 
   ShowDialog();
   List<DataGridViewRow> res = new List<DataGridViewRow>();
   if(_closedByTransferButton)
   {
       for(int i = 0;i<grid.Rows.Count;i++)
           if((bool)grid.Rows[i].Cells["checkboxColumn"].Value)
               res.Add(grid.Rows[i]);
   }
   return res;
}

-And the Click event of your Transfer button should be:

private void tranferButton_Click(object sender, EventArgs e)
{
   _closedByTransferButton = true;
   Close();
}

Hope this helps.

Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69
  • i want i have one form which called Main Form now i want daily data which was making by workers so user click on Button when cliked button 2nd form "Get Data Form" open and user select some data and Transfer on Main Form but Transfer in gridview to gridview by 2 Forms @trippino my English not so good i hope u understand – user2491383 Sep 18 '13 at 18:47
  • no I m not trying your update code but I do my self by tempory Table checked rows insert in temp Table and I'm calling on next form by select Query – user2491383 Sep 30 '13 at 06:41