A
AAJ
Hi all
I'm new to all this object programming, and I'm after a bit of advice on a
specific problem. I wonder if anyone can help?
I have a user control and on it are some text boxes bound to a database .
At a particular time I want to add it to a forms control, have the user work
on it, and then when the user is done remove it and clear up the memory.
Is there a recognised way/pattern of doing this type of thing
i.e. if I have a form with the following function
private void test()
{
UCQuestion Question1 = new UCQuestion(1,"Sample Question Test");
this.Controls.Add(Question1);
}
When the question has been answered I want to remove Question1 from the form
collection (and from memory) i.e. when the user closes the control.
I can put a button on the user control to generate an event, but back in the
form, Question1 is only within scope in the test function, so the event
handler that I write cannot see 'Question1'. I know I could make UCQuestion
Question1 global within the class, but I will have many dynamic Questions,
and so I need to be able to create and remove them dynamically.
So I'm wondering if Is it possible to use the event sender or args to find
the Specific object within the form controls and remove it.
I'm sure that this must be a faily common thing to want to do, so I'm
wondering if there is a best practice out there.
many thanks in advance
Andy
I'm new to all this object programming, and I'm after a bit of advice on a
specific problem. I wonder if anyone can help?
I have a user control and on it are some text boxes bound to a database .
At a particular time I want to add it to a forms control, have the user work
on it, and then when the user is done remove it and clear up the memory.
Is there a recognised way/pattern of doing this type of thing
i.e. if I have a form with the following function
private void test()
{
UCQuestion Question1 = new UCQuestion(1,"Sample Question Test");
this.Controls.Add(Question1);
}
When the question has been answered I want to remove Question1 from the form
collection (and from memory) i.e. when the user closes the control.
I can put a button on the user control to generate an event, but back in the
form, Question1 is only within scope in the test function, so the event
handler that I write cannot see 'Question1'. I know I could make UCQuestion
Question1 global within the class, but I will have many dynamic Questions,
and so I need to be able to create and remove them dynamically.
So I'm wondering if Is it possible to use the event sender or args to find
the Specific object within the form controls and remove it.
I'm sure that this must be a faily common thing to want to do, so I'm
wondering if there is a best practice out there.
many thanks in advance
Andy