473,804 Members | 3,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView datasource ?

dear all,

Is there an easy way to bind a treeview control with an XML object as
datasource?
In a similar way as the dataset is doing, and build columns accroding to
XML node, I could imagine a treeview which build its notes accordind to XML
object too

how can I do that?

thanks for wour help
serge
Jul 21 '05 #1
2 8047
serge calderara wrote:
dear all,

Is there an easy way to bind a treeview control with an XML object as
datasource?
In a similar way as the dataset is doing, and build columns accroding to
XML node, I could imagine a treeview which build its notes accordind to XML
object too

how can I do that?

thanks for wour help
serge


Funny you should ask, becase I am working on a project where i do just
that. I am retrieving XML data from a web service and I use that to
populate a tree control. My XML data is highly tailored to the
application, which is why you see special parsing in the AddNode method.

private void populateBox()
{
//Object[] objarray = lc.AllLocations ();

lcx = lc.LocationsTop Level();

try
{
// SECTION 1. Create a DOM Document and load the XML data into it.
XmlDocument dom = new XmlDocument();

//dom.AppendChild (lcx);

//dom.Load(textBo x1.Text);
dom.AppendChild (dom.ImportNode (
lcx
,true));

//inXmlNode=inXml Node.SelectSing leNode("//position[@row='1']");

// SECTION 2. Initialize the TreeView control.
treeView1.Nodes .Clear();
treeView1.Nodes .Add(new TreeNode(dom.Do cumentElement.N ame));
TreeNode tNode = new TreeNode();
tNode = treeView1.Nodes[0];

// SECTION 3. Populate the TreeView with the DOM nodes.
AddNode(dom.Doc umentElement, tNode);
treeView1.Expan dAll();

}
catch(XmlExcept ion xmlEx)
{
MessageBox.Show (xmlEx.Message) ;
}
catch(Exception ex)
{
MessageBox.Show (ex.Message);
}

}


private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;

int i;

// Loop through the XML nodes until the leaf is reached.
// Add the nodes to the TreeView during the looping process.

try
{

if (inXmlNode.HasC hildNodes)
{
nodeList = inXmlNode.Child Nodes;
for(i = 0; i<=nodeList.Cou nt - 1; i++)
{
xNode = inXmlNode.Child Nodes[i];

if(xNode.Name== "position")
inTreeNode.Node s.Add(new TreeNode(
xNode.Attribute s.GetNamedItem( "row").InnerTex t.ToString() + " " +
xNode.Attribute s.GetNamedItem( "bay").InnerTex t.ToString() + " " +
xNode.Attribute s.GetNamedItem( "level").InnerT ext.ToString()
));
if(xNode.Name== "client")
inTreeNode.Node s.Add(new TreeNode(
xNode.Attribute s.GetNamedItem( "id").InnerText .ToString()));

if(xNode.Name== "partnum")
inTreeNode.Node s.Add(new TreeNode(
xNode.InnerText ));


tNode = inTreeNode.Node s[i];
AddNode(xNode, tNode);
}
}
else
{
// Here you need to pull the data from the XmlNode based on the
// type of node, whether attribute values are required, and so forth.
//inTreeNode.Text = (inXmlNode.Oute rXml).Trim();
//inTreeNode.Text = (inXmlNode.Inne rText).Trim();
if(inXmlNode.Na me=="position")
inTreeNode.Node s.Add(new TreeNode(
inXmlNode.Attri butes.GetNamedI tem("row").Inne rText.ToString( ) + " " +
inXmlNode.Attri butes.GetNamedI tem("bay").Inne rText.ToString( ) + " " +
inXmlNode.Attri butes.GetNamedI tem("level").In nerText.ToStrin g()
));

}

}
catch (Exception e)
{
Debug.WriteLine (e.ToString());
}
}
Jul 21 '05 #2
I have a crystal ball...
Its is strange that XML is a hierarchical structure of any type of data an
nothing is existing on just placeing an XML source as a datasource for a
treeview, as treeview is really matching that XMl node.

Have you seen or heard something in 2005 beta 2 on that topic ?

"ja*****@texeme .com" wrote:
serge calderara wrote:
dear all,

Is there an easy way to bind a treeview control with an XML object as
datasource?
In a similar way as the dataset is doing, and build columns accroding to
XML node, I could imagine a treeview which build its notes accordind to XML
object too

how can I do that?

thanks for wour help
serge


Funny you should ask, becase I am working on a project where i do just
that. I am retrieving XML data from a web service and I use that to
populate a tree control. My XML data is highly tailored to the
application, which is why you see special parsing in the AddNode method.

private void populateBox()
{
//Object[] objarray = lc.AllLocations ();

lcx = lc.LocationsTop Level();

try
{
// SECTION 1. Create a DOM Document and load the XML data into it.
XmlDocument dom = new XmlDocument();

//dom.AppendChild (lcx);

//dom.Load(textBo x1.Text);
dom.AppendChild (dom.ImportNode (
lcx
,true));

//inXmlNode=inXml Node.SelectSing leNode("//position[@row='1']");

// SECTION 2. Initialize the TreeView control.
treeView1.Nodes .Clear();
treeView1.Nodes .Add(new TreeNode(dom.Do cumentElement.N ame));
TreeNode tNode = new TreeNode();
tNode = treeView1.Nodes[0];

// SECTION 3. Populate the TreeView with the DOM nodes.
AddNode(dom.Doc umentElement, tNode);
treeView1.Expan dAll();

}
catch(XmlExcept ion xmlEx)
{
MessageBox.Show (xmlEx.Message) ;
}
catch(Exception ex)
{
MessageBox.Show (ex.Message);
}

}


private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;

int i;

// Loop through the XML nodes until the leaf is reached.
// Add the nodes to the TreeView during the looping process.

try
{

if (inXmlNode.HasC hildNodes)
{
nodeList = inXmlNode.Child Nodes;
for(i = 0; i<=nodeList.Cou nt - 1; i++)
{
xNode = inXmlNode.Child Nodes[i];

if(xNode.Name== "position")
inTreeNode.Node s.Add(new TreeNode(
xNode.Attribute s.GetNamedItem( "row").InnerTex t.ToString() + " " +
xNode.Attribute s.GetNamedItem( "bay").InnerTex t.ToString() + " " +
xNode.Attribute s.GetNamedItem( "level").InnerT ext.ToString()
));
if(xNode.Name== "client")
inTreeNode.Node s.Add(new TreeNode(
xNode.Attribute s.GetNamedItem( "id").InnerText .ToString()));

if(xNode.Name== "partnum")
inTreeNode.Node s.Add(new TreeNode(
xNode.InnerText ));


tNode = inTreeNode.Node s[i];
AddNode(xNode, tNode);
}
}
else
{
// Here you need to pull the data from the XmlNode based on the
// type of node, whether attribute values are required, and so forth.
//inTreeNode.Text = (inXmlNode.Oute rXml).Trim();
//inTreeNode.Text = (inXmlNode.Inne rText).Trim();
if(inXmlNode.Na me=="position")
inTreeNode.Node s.Add(new TreeNode(
inXmlNode.Attri butes.GetNamedI tem("row").Inne rText.ToString( ) + " " +
inXmlNode.Attri butes.GetNamedI tem("bay").Inne rText.ToString( ) + " " +
inXmlNode.Attri butes.GetNamedI tem("level").In nerText.ToStrin g()
));

}

}
catch (Exception e)
{
Debug.WriteLine (e.ToString());
}
}

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5606
by: Craig | last post by:
Is there a way to "tie" or "bind" an XmlDocument to a treeView, so the changes in the treeView can automatically be reflected in the XmlDocument object? (Like DataSource for a ListBox) If not, what's the best way to reflect the changes from the treeView back to the XmlDocument? Background: I'm trying to read in an xml file and display some of the elements in a treeview and have the XmlDocument be the datasource and the treeview just...
2
3349
by: Ryo | last post by:
Hello ! I have an XmlDocument in memory and I want to put this document as datasource of my treeview. How to do this ? Thanks.
0
1240
by: Ryo | last post by:
Hello ! I have this simple aspx page: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test_treeview.aspx.cs" Inherits="test_treeview" Title="Treeview" %> <asp:Content ID="cntCorpCentre" ContentPlaceHolderID="cphCorpCentre" EnableViewState="false" RunAt="Server"> <asp:TreeView ID="Organigramme" SkinID="Organigramme" EnableViewState="false" RunAt="server" />
2
985
by: serge calderara | last post by:
dear all, Is there an easy way to bind a treeview control with an XML object as datasource? In a similar way as the dataset is doing, and build columns accroding to XML node, I could imagine a treeview which build its notes accordind to XML object too how can I do that?
0
1220
by: Michael Lewis | last post by:
Does anyone know if it is possible to bind a gridview to a treeview. Ie. I want to be able to expand a treeview node and see a separate gridview for each node. The gridview will be filtered by a parameter specified by the treeview datasource (ie. ID). I have looked everywhere on the net and it seems that it cannot be done, or at least very difficult. Cheers
5
5825
by: Paul | last post by:
Hi, I am a self taught VBA programmer, and I'm trying to learn VB2005 Express (The price was right). I like the look of the treeview control, and I'd like to use it as a menu system for my users, the options they are allowed to see are all different and specified in a MSACCESS table. Can I populate a Treeview directly from my MSAccess table ? I can then of course filter the table to only show that users options.
26
8533
by: JJ | last post by:
Is there any way you can expand a parent node on the treeview control _without a postback_ by clicking on the node text (NOT clicking the expand image URL) ? I want to format the treeview node to look like a column of buttons that expand to show the child nodes (if there are child nodes) qithout a postback. I don't want to display the plus/minus or any other expand/collapse graphic. ?
3
4076
by: =?Utf-8?B?TGVzbGll?= | last post by:
Using Visual Studio 2005 SP1 I am attempting to dynamically load a treeview control. I create an XmlDataSource and then load the data source using XmlDataSource.Data. I Load my XML string into this property using the code shown below. However if I change the values in the XML string that I am loading into XmlDataSource.Data and then run the web, the changes do not show up. The only way to get the changes to show up is to rebuild the...
0
7176
by: Dennis Francek | last post by:
Hello I have populated a treeview from my dataset and by clicking in the treeview i want to get the corresponding table shown in a datagridview. Ive managed this by looking at each DataRow and child rows and added the nodes with a columnname from each datarow. At the same time i have put in a tag at each treenode with a filter string and the current table im looking at as a string to use for later so i can create a datatable and set a filter...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.