14
Answers

Problem creating Form

Photo of Santiago Firezzi

Santiago Firezzi

14y
10.8k
1
Hi everyone....
This is my problem

     public partial class Expedientes : UserControl
{
FormX AddNewForm = new FormX();

 private void button1_Click(object sender, EventArgs e)
{
AddNewForm.Show();
}

private void button2_Click(object sender, EventArgs e)
{
AddNewForm.Close();
}
}

When I close the form and try to reopen it, this error occurs:
Can not access a disposed object.

How I solve can it?

Thanks people

Answers (14)

1
Photo of Frogleg
NA 7.9k 33k 14y

Attachment Example2.zip

Yes it is adding duplicates - check this also
Accepted
0
Photo of Santiago Firezzi
NA 15 10.8k 14y
Try...
Modify the code
And look what happens when you add 2 or more rows...
I can repair the problem, so it's done
Thanks a lot for your assistance
Grettings
0
Photo of Frogleg
NA 7.9k 33k 14y
do you mean
Form2 agregardatos closes and then cannot be used again ?
change
agregardatos.Close();
 to
agregardatos.Hide();
 
0
Photo of Santiago Firezzi
NA 15 10.8k 14y

Attachment Example.zip

Here is...
0
Photo of Santiago Firezzi
NA 15 10.8k 14y
Stay here a moment...
In a moments I upload a project with my problem
0
Photo of Frogleg
NA 7.9k 33k 14y

Attachment XForm.zip

Look at this
0
Photo of Santiago Firezzi
NA 15 10.8k 14y
No, I have 2 forms

The UserControl have the datagrid with a DataSet and another things.

I use the XForm to insert a new row in the UserControl.
The data comes from the text boxes in the XForm
0
Photo of Frogleg
NA 7.9k 33k 14y

So you have 3 forms, user control, formX and Xform.
user control and Xform are already open ?
You want  Xform textbox.text to be entered into database by clicking button on formX
0
Photo of Santiago Firezzi
NA 15 10.8k 14y
I need the XForm because otherwise I will have many controls on the Control.

There is only 1 TextBox are like 15 ...
0
Photo of Frogleg
NA 7.9k 33k 14y
Why do you need formX
0
Photo of Santiago Firezzi
NA 15 10.8k 14y
well I'll explain:

I am working with a database in this UserControl and I need a form to add data.

to that is this

diagram.gif

Do you understand me?
0
Photo of Frogleg
NA 7.9k 33k 14y

Button 1 on formX is private - so you can't access it from form 1
Can you explain why you need to click FormX.button1 from form1
0
Photo of Santiago Firezzi
NA 15 10.8k 14y
Oh sorry but doesn't work because the button have's another instructions... I forget it

I edit the code:

    public partial class Expedientes : UserControl
{
FormX AddNewForm = new FormX();

 private void button1_Click(object sender, EventArgs e)
{
AddNewForm.button1.Click+= new EventHandler(XEvent);
AddNewForm.Show();
}

private void button2_Click(object sender, EventArgs e)
{
AddNewForm.Close();
}

private void XEvent(object sender, EventArgs e)
{
this.textBox1.Text="Some Word";
}
}

0
Photo of Frogleg
NA 7.9k 33k 14y

  public partial class Expedientes : UserControl
{
//FormX AddNewForm = new FormX();//1*  move to button event

 private void button1_Click(object sender, EventArgs e)
{
FormX AddNewForm = new FormX();
AddNewForm.Show();
}

private void button2_Click(object sender, EventArgs e)
{
AddNewForm.Close();//2*  or use AddNewForm.Hide()
}
}