2
Reply

Copying a control to a new form

lumumba14

lumumba14

Jun 30 2004 6:31 AM
1.5k
Hello, I am using a grid control in a form which displays some data to the user. I have added some code to its Click event, which displays some data from this control to textboxes in the new form. The data is passed to the new form through its constructor and it works ok. But then I want to pass the complete control from the first form to the second, along with its data, again through the second form's constructor. The control is passed, it is displayed ok, but it is lost from the main form. Here is what I do: class FirstClass : System.Windows.Forms.Form { //... private void grid_Click(object sender, EventArgs e) { SecondClass newOne = new SecondClass(txt, grid); newOne.Show(); //the SecondClass form displays ok } } class SecondClass : System.Windows.Forms.Form { //.. private Grid theGrid; private string theString; public SecondClass(string txt, Grid grid) { // //this is the second constructor of the second class // InitializeComponent(); theGrid = grid; theString = txt; } private void SecondClass_Load(object sender, EventArgs e) { txtBox1.Text = txt; //works fine this.Controls.Add(theGrid); //works fine, the grid is displayed ok with all the data //from the first form, but it is lost from the first form } }//end SecondClass Still haven't found a solution, could anyone help me with this problem?

Answers (2)