473,327 Members | 2,071 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,327 software developers and data experts.

Tree view recursive

I have tried for a recursive tree.

Please help me.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. private void PopulateReport()
  2.         {
  3.             List<ListItems> siteData = new List<ListItems>();
  4.             DataTable dt = GetAllData4();
  5.  
  6.             foreach (DataRow dr in dt.Rows)
  7.             {
  8.                siteData.Add(new ListItems(int.Parse(dr["MainId"].ToString()),dr["MainName"].ToString(),int.Parse(dr["SecondId"].ToString()),dr["SecondName"].ToString(),int.Parse(dr["ThirdId"].ToString()),dr["ThirdName"].ToString()));
  9.             }
  10.             var nodes = siteData.Find(x => x.MainId ==int.Parse(dt.Rows[0]["MainId"].ToString()));
  11.             if (nodes != null)
  12.             {
  13.                 RadTreeNode radTreeNode = new RadTreeNode(nodes.MainName, nodes.MainId.ToString());
  14.                 radTree1.Nodes.Clear();
  15.                 radTree1.Nodes.Add(radTreeNode);
  16.                 BindTree(siteData, radTreeNode);
  17.             }
  18.         }
  19.  
  20.         private void BindTree(IEnumerable<ListItems> list, RadTreeNode parentNode)
  21.         {
  22.             var nodes = list.Where(x => parentNode == null ? x.MainId == 0 : x.MainId ==int.Parse(parentNode.Value));
  23.             foreach (var node in nodes)
  24.             {
  25.                 RadTreeNode radTreeNode = new RadTreeNode(node.MainName, node.MainId.ToString());
  26.                 if (parentNode == null)
  27.                 {
  28.                     radTree1.Nodes.Add(radTreeNode);
  29.                 }
  30.                 else
  31.                 {
  32.                     parentNode.Nodes.Add(radTreeNode);
  33.                 }
  34.                 BindTree(list, radTreeNode);
  35.             }
  36.         }
  37.  
  38.  
  39. public DataTable GetAllData4()
  40.         {
  41.             return GetDataTable(@"SELECT T1.*,T2.SECONDID,T2.SECONDNAME,T3.THIRDID,T3.THIRDNAME FROM T1 INNER JOIN T2 ON T1.MAINID=T2.MAINID
  42.                                                 LEFT OUTER JOIN T3 ON T2.SecondId=T3.SecondId ORDER BY T1.MAINID");
  43.         }
  44.  
  45.  
  46. public class ListItems
  47.         {
  48.             private int _mainId;
  49.             private string _mainName;
  50.             private int _secondId;
  51.             private string _secondName;
  52.             private int _thirdId;
  53.             private string _thirdName;
  54.  
  55.             public int MainId
  56.             {
  57.                 get { return _mainId; }
  58.                 set { _mainId=value ; }
  59.             }
  60.             public string MainName
  61.             {
  62.                 get { return _mainName; }
  63.                 set { _mainName = value; }
  64.             }
  65.             public int SecondId
  66.             {
  67.                 get { return _secondId; }
  68.                 set { _secondId = value; }
  69.             }
  70.             public string SecondName
  71.             {
  72.                 get { return _secondName; }
  73.                 set { _secondName = value; }
  74.             }
  75.             public int ThirdId
  76.             {
  77.                 get { return _thirdId; }
  78.                 set { _thirdId = value; }
  79.             }
  80.             public string ThirdName
  81.             {
  82.                 get { return _thirdName; }
  83.                 set { _thirdName = value; }
  84.             }
  85.  
  86.             public ListItems(int mainId,string mainName,int secondId,string secondName,int thirdId,string thirdName)
  87.             {
  88.                 _mainId = mainId;
  89.                 _mainName = mainName;
  90.                 _secondId = secondId;
  91.                 _secondName = secondName;
  92.                 _thirdId = thirdId;
  93.                 _thirdName = thirdName;
  94.             }
  95.         }
Jun 18 '12 #1
0 1534

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

Similar topics

4
by: ghanley | last post by:
Hi Guys, I need some help with a problem related to the looping through a recordset to display on a tree view control. My table has no Primary key - because duplicates are allowed. ID ...
1
by: Jesper DK | last post by:
Hi, I have docked a tree view to the left on a form. When I start to populate this tree view with nodes, a horizontal scroll box appears in the bottom of the tree view even though thee tree...
5
by: mittal.pradeep | last post by:
I have a table with 5 columns. Every column represents a level in a hierarchy. I need to populate a windows forms tree view control using this table. Also Is there a recursive way to populate a...
1
by: Kaye | last post by:
It seems that when I dynamically resize items in a tree-view control, using TVM_SETITEM and the TVITEMEX iIntegral member, things go awry. The window draws properly, but it seems like the RECTs for...
10
by: dwok | last post by:
Does anyone know of a good article that discusses creating a "Tree View" control in ASP.NET? Or perhaps a Tree View Control that comes with source code? I have come across a lot of tree controls...
5
by: Pavan | last post by:
My goal is to accomplish the tooltip functionality for all the neodes in a tree view and i have the following three Events in my C# application. Name of my TreeView Control (AITreeView) 1)...
0
by: rinishrk | last post by:
Hi, I have a web application that contains subfolders Admin and User with related webpages inside them. Within the Admin folder I have a page containing a Tree View Control.I want this tree view...
0
by: Brishti09 | last post by:
I am tring to search for an existing nodes in tree view and change its forecolor. I am matching the tag value of the node. The program is able to search recursively through the tree and change the...
3
by: gmail | last post by:
Hi Friends, Can any body suggest me on this. I am working on .NET 2005 Frame work 2.0 . I am facing problem using the tree stucture. I created the site map.Now i want use the site map in every...
1
by: happy.john1234 | last post by:
Hi, i have got large xml file which i have to show in tree view windows form.I tried with loading all those data at once to tree view but it took a long time to render that tree view.Now i am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.