473,383 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

populate a Treeview from XML file

JustRun
127 100+
Hi,
I have this XML file , converted from a database view
Expand|Select|Wrap|Line Numbers
  1.  
  2. <Parent>
  3.   <Parent name="Category">
  4.     <Child name="SubCat01" level="1">
  5.       <Child name="SubCat02" level="2">
  6.         <Child name ="Product01-01" level="3"/>
  7.         <Child name ="Product01-02" level="3"/>
  8.         <Child name ="Product01-03" level="3"/>
  9.       </Child>
  10.     </Child>
  11.     <Child name="SubCat02" level="1">
  12.       <Child name="Product02-01" level="2"/>
  13.       <Child name="Product02-02" level="2"/>
  14.     </Child>
  15.   </Parent>
  16. </Parent>
  17.  
  18.  
Regarding that I have an unlimited Childs.

Expand|Select|Wrap|Line Numbers
  1. TreeNode stateNode;
  2. TreeNode regionNode;
  3.  
  4. XElement doc = XElement.Load(txtXMLPath.Text);
  5.  
  6. int level = 1;
  7. foreach (XElement parent in doc.Descendants("Parent"))
  8.     stateNode = treeProduct.Nodes.Add(parent.Attribute("name").Value);
  9.     for (int i = 0; i <= level; i++)
  10.     {
  11.          XName childNod = "Child" + level.ToString();
  12.          foreach (XElement child in parent.Descendants("Child"))
  13.          {
  14.               regionNode = stateNode.Nodes.Add(child.Attribute("name").Value);
  15.           }
  16.  
  17.           stateNode = regionNode;
  18.           //level++;
  19.       }
  20. }
  21.  
Thanks
Feb 17 '10 #1
3 3693
tlhintoq
3,525 Expert 2GB
I have xxx, then do yyy then zzz happens. Here's my code ...
Ok. You know what you have.
What you don't have is a question. Nobody here knows why you posted this since you haven't asked anything. What is it you are looking for?
I recommend you read the FAQ about How to ask a good question so the volunteers will be able to help you.
Feb 17 '10 #2
JustRun
127 100+
yes, you are right, Sorry for that.

Actually, I have this database view:

================================================== ====|
TableId | ParentId | ChildId | ParentName | ChildName |
newId() | uniqueIdentifier | uniqueIdentifier | nvarchar | nvarchar |
================================================== ====|

what I need is to display this view in a treeview like this:

Parent
Child1
child1-1
child1-2
Child2
child2-1
child2-2

and so on .. Regarding that the user can insert unlimited children (N categogry)

I thought to convert this to an XML file then read it in the treeview, but none of my ways give me the accurate result

So, I need to read my stored data in a treeview,.
Please provide me with the best way to do this whether XML or directly from the database or dataset ... whatever.

Thanks
Feb 17 '10 #3
JustRun
127 100+
I think I got itttttttttttt

I'll put it here - Just finish then give it to u Bytes :D
Feb 18 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: T.H.M | last post by:
This is the all code. Very simple and short. I need to populate a treeView in aspx page (web form) from XML file. I get en completion error:No overload for method 'TreeNode' takes '1' arguments ....
4
by: Mike | last post by:
how can i populate a treeview from a database? websites with examples would help.
9
by: Marina | last post by:
Hello! I have a database with some customers. Each one of them has 3 other customers under him etc. (something like an MLM system). Now, I want to create a treeview with this. Eg. C1 C11...
2
by: Jack | last post by:
Hello, I am trying to populate a Treeview from a XML File. XML File: <Papers> <Paper> <PaperName>New York Times</PaperName>
2
by: Dave Wurtz | last post by:
All, I have a treeview on my form that has a lot of nodes on it. I would like to populate this treeview on another thread so my form will still paint while it is being populated. I have...
1
by: john wright | last post by:
I have my code done to populate a treeview, but when I move it to the backgroundworker I get an error "Action being performed on this control is being called from the wrong thread. Marshal to the...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
0
by: Patrick | last post by:
Hi, Im trying to populate my treeview control onmy webpage with the information that is stored in a xml file, but i cant seem to find any good references about it. The xml file looks like this. ...
2
by: thanneman | last post by:
Hello all, First off all, I appollogize for my englisch. I have a problem. I have a table in my sql database with 2 fields. Field 1 is an ID, and Field 2 contains the complete file locations. ...
0
by: xmail123 | last post by:
How to populate a treeview from a dataset I am very new to C#. I need to create a Windows form that will read a SQL table and populate a treeview. I can connect to the DB, create the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.