Incorrect instance in .NET 2.0 Form Shown event

V

Victory

i am using the Shown event for a form. It is in .NET 2.0. It is an event
that occurs when a form is displayed. I wanted to use this event since i
needed the processing of data to occur after the form is displayed. To
use it, i had to wire this even to the form: this.Shown += new
EventHandler(myMethod);
In another method (public), which i call from the main form, i pass in
an object then set it to the form's instance variable: i.e.
this.EditObject = passed in object;
Then i invoke the function from main, the first time, the object is
passed. The second time i invoke the form with a different object,
this.EditObject has the correct object instance (i.e. the new one), when
i break in the Shown event handler i.e. myMethod, the install
this.EditObject shows the first invocations object. I sounds like a .NET
bug, has anybody seen this.

in the Form Constructor:

this.Shown += new EventHandler(myMethod);

public void ShowEditDialog(MyObject CurrentObject)
{
this.EditObject = CurrentObject;
ShowDialog();
}

private void myMethod(object sender, EventArgs e)
{
if (this.EditObject.Enabled == true)
{
// .... on second invocation, the previous
// instance of EditObject exists here and not
// the new one.
}
}


Mars
 
N

Nicholas Paldino [.NET/C# MVP]

Mars,

You aren't showing the declaration of EditObject (which I am thinking
might be static, for some reason), or how you are calling ShowEditDialog.
You might not be calling that correctly either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top