Guest User

Untitled

a guest
Jan 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. if (richTextBox1.Text != "")
  2. {
  3. mainForm newMainForm = new mainForm();
  4. newMainForm.dataGridView1.ColumnCount = 3;
  5. newMainForm.dataGridView1.Columns[0].Name = "Product ID";
  6. newMainForm.dataGridView1.Columns[1].Name = "Product Name";
  7. newMainForm.dataGridView1.Columns[2].Name = "Product Price";
  8.  
  9. string[] row = new string[] { "1", "Product 1", "1000" };
  10. newMainForm.dataGridView1.Rows.Add(row);
  11. row = new string[] { "2", "Product 2", "2000" };
  12. newMainForm.dataGridView1.Rows.Add(row);
  13. row = new string[] { "3", "Product 3", "3000" };
  14. newMainForm.dataGridView1.Rows.Add(row);
  15. row = new string[] { "4", "Product 4", "4000" };
  16. newMainForm.dataGridView1.Rows.Add(row);
  17. }
  18.  
  19. subForm sub = new SubForm();
  20. sub.Show(); // or however you have done it
  21.  
  22. private mainForm _parent;
  23.  
  24. internal void RegisterParent(mainForm form)
  25. {
  26. // error handling of course, make sure form is not null, or you don't already have a parent
  27. this._parent = form;
  28. }
  29.  
  30. sub.RegisterParent(this);
  31.  
  32. if (richTextBox1.Text != "")
  33. {
  34. _parent.dataGridView1.ColumnCount = 3;
  35. _parent.dataGridView1.Columns[0].Name = "Product ID";
  36. _parent.dataGridView1.Columns[1].Name = "Product Name";
  37. _parent.dataGridView1.Columns[2].Name = "Product Price";
  38.  
  39. string[] row = new string[] { "1", "Product 1", "1000" };
  40. _parent.dataGridView1.Rows.Add(row);
  41. row = new string[] { "2", "Product 2", "2000" };
  42. _parent.dataGridView1.Rows.Add(row);
  43. row = new string[] { "3", "Product 3", "3000" };
  44. _parent.dataGridView1.Rows.Add(row);
  45. row = new string[] { "4", "Product 4", "4000" };
  46. _parent.dataGridView1.Rows.Add(row);
  47. }
Add Comment
Please, Sign In to add comment