Samiul Aman wrote:
private void button1_Click(object sender, EventArgs e)
{
UserControl userControl = new UserControl();
userControl.Refresh();
}
Is this new
UserControl
being added to the form anywhere? If you don't do a
this.Controls.Add(userControl);
and set the control's other properties (location, visible, etc) then it'll never be drawn by the form. Are you sure that you want to create a new User Control for every button click instead of just creating/adding one when the form is created?
[EDIT]
You probably meant to instantiate a
new MyDerivedUserControl()
instead of just a
new UserControl()
there as well. That will definitely cause you grief :)
[/EDIT]
Samiul Aman wrote:
public override void Refresh()
{
PopulateTreeView();
}
It also might be a good idea to call
base.Refresh()
after you've done your own custom stuff.
[RESPONSE TO COMMENT]
Samiul Aman wrote:
Is it OK?
I don't know, does it work? If you have a
this.userControl
variable then I have to ask: does a new user control get added to a new tab page every time the button is clicked, or is there only one user control that should be refreshed every time the button is clicked? If there's only one user control then there's definitely no need to call
new UserControl()
in the click handler.
My comment about calling
base.Refresh()
is that you overrode the default behavior for that method in you own class. After the call to
PopulateTreeView();
you should consider calling the base version of the method so that the user control can do what it normally does.
[/RESPONSE TO COMMENT]