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();

       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)

       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;


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??

Edited by mike_2000_17: Fixed formatting

9 Years
Discussion Span
Last Post by sknake

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.