Hi,
I have to create a project in C# in which i have to create a XML Tree View, select a xml file from hard drive(System) it is displayed as Tree View on winform.

When a user selects a particular node/element in the tree view,its attributes and values have to be displayed in list box and text box respectively.

Till now i have done a part of it like selecting it from Openfiledialog(Browse) showing it in tree View and all the attributes related to the XML file in list box.
But i don't know how to put a code in
private void treeViewObj_AfterSelect(object sender, TreeViewEventArgs e)
{
//what to write here.
}
Please help me out as early as possible..
Thanks in advance.:)

Recommended Answers

All 2 Replies

Hello, rasingh24.
I suppose, this should be helpful for you: TreeViewEventArgs..::.Node Property

P.S. All you have to do to get any data of the selected node - is extract it from e.Node .

Thanks for the reply......
I have already gone through the link you provided but since i am new to C# i am not able to get how these work..
i mean what to put in the AfterSelect() method..i have written some code mailing you up...please correct me if i am wrong....

private void treeViewObj_AfterSelect(object sender, TreeViewEventArgs e)
{
listBoxeg.Items.Clear();//Listbox where i have to show the attributes of the node selected in the treeview.
XmlNode xNode = xdoc.DocumentElement;
TreeNode selNode = e.Node;
textBox1.Text = selNode.Text;//Textbox where i want to show the value of the attribute.


if (e.Node.TreeView.SelectedNode != null)
{
foreach (XmlAttribute attribute in xNode.Attributes)
{
ShowinListboxandTextbox(attribute, selNode.Nodes);
}
}
}


private void ShowinListboxandTextbox(XmlNode xmlNode,TreeNodeCollection treeNodecollect)
{
TreeNode treeNodeobj = treeNodecollect.Add(xmlNode.Name);


switch (xmlNode.NodeType)
{
case XmlNodeType.Attribute:
treeNodeobj.Text = "ATTRIBUTE: " + xmlNode.Name;
listBoxeg.Items.Add(treeNodeobj.Text);
break;
case XmlNodeType.CDATA:
treeNodeobj.Text = xmlNode.Value;
listBoxeg.Items.Add(treeNodeobj.Text);
break;
}//switch
}//ShowinListboxandTextbox

But this dosent work :( Please correct me if you can help out....:S
Thanks...:sad:

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.