Hi,
i have a project in which i created two classes TreeDisplayform(Form.cs) and MytreeNode class in same namespace. TreeDisplay class contains all the GUI related stuff like Browse button textbox, TReeView. I want the user to select a XML file through browse button which will be displayed in textbox.The Xml file selected will be displayed in Treeview on winform. Now i want to separate the GUI part from business logic(where i am creating treenode and adding nodes to tree) thats why i created the MytreeNode class. I am passing string filename from the FileOpenDialogue in Browse button.

//Browse button click event
 if (open.ShowDialog(this) == DialogResult.OK)
        {   txtFileName.Text = open.FileName;
            new MytreeNodeClass(open.FileName);//this variable gives the name of selected xml file to MytreeNodeclass
        }

and MytreeNodeclass code is here

public class MytreeNodeClass
{
    readonly TreeDisplayForm formObj = new TreeDisplayForm();//created object of Treedisplayform class

    public MytreeNodeClass(string filepath)
    {
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(filepath);
        formObj.passingTreeview(xmlDocument);

       XmlNode xNode = xmlDocument.DocumentElement;
     AddNodes(xNode, formObj.tNodeObj);//calling treenode of Treedisplayform class            
    }

and the passingTreeview() function is here in Treedisplayform class

public void passingTreeview(XmlDocument xmlDocument)
    {
       treeView1.Nodes.Clear();

       if (xmlDocument.DocumentElement != null)
       if (true) treeView1.Nodes.Add(new TreeNode(xmlDocument.DocumentElement.Name));

        tNodeObj = new TreeNode();//Declared public TreeNode tNodeObj; on top in TreeDisplayform class.
        tNodeObj = treeView1.Nodes[0];
        XmlNode xNode = xmlDocument.DocumentElement;

        treeView1.Nodes[0].Expand();
        treeView1.CollapseAll();
    }//passingTreeview

but i am unable to see the treeview in the winform.The code runs successfully in TreeDisplayform.cs but on separating there is no error but result is not shown.
Can you tell me where i am getting wrong??
Thanks....

If you post a full project sample here I will be willing to take a look at it. With delayed initialization and how .NET creates controls this could be one of a number of things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.