UserControl/TreeView Problem....Not getting result during runtime..
Posted
by Samiul
on Stack Overflow
See other posts from Stack Overflow
or by Samiul
Published on 2010-05-26T05:20:16Z
Indexed on
2010/05/26
5:41 UTC
Read the original article
Hit count: 250
Hi all,
My problem is, I'm using a TreeView in a UserControl. While debugging, I can see the results are adding in the TreeView but it's not happening when I'm using that UserControl onto my MainForm. The UserControl containing the TreeView remains blank during runtime of the main application. I've also referenced the UserControl project with my Main project. Here I'm giving my code for helping me out.
Thanks in advance.
Code:
In the UserControl class:
public override void Refresh()
{
PopulateTreeView();
}
private void PopulateTreeView()
{
TreeNodeCollection treeNodeCollection;
treeNodeCollection = CreateParentNode("My Information");
CreateChildNode(treeNodeCollection, "Name");
CreateChildNode(treeNodeCollection, "Address");
this.Update();
myTreeView.ExpandAll();
}
private TreeNodeCollection CreateParentNode(string parentNode)
{
TreeNode treeNode = new TreeNode(parentNode);
myTreeView.Nodes.Add(treeNode);
return treeNode.Nodes;
}
private void CreateChildNode(TreeNodeCollection nodeCollection, string itemName)
{
TreeNode treeNode = new TreeNode(itemName);
nodeCollection.Add(treeNode);
}
In my MainForm:
private void button1_Click(object sender, EventArgs e)
{
UserControl userControl = new UserControl();
userControl.Refresh();
}
© Stack Overflow or respective owner