Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting data in following format from Datatable as

Protection_1.Record.Trip.TripRecord1.Year
Protection_1.Record.Trip.TripRecord1.Month
Protection_1.Record.Trip.TripRecord1.Date
Protection_1.Record.Trip.TripRecord1.Hour
Protection_1.Record.Trip.TripRecord1.Min
Protection_1.Record.Trip.TripRecord1.Sec
Protection_1.Record.Trip.TripRecord1.mSec
Protection_1.Record.Trip.TripRecord1.Pickup_Setting_String

Same needs to plotted using tree in Treeview.

What I have tried:

I tried to build following logic
TreeNode node = null;
TreeNodeCollection nodes = Treeview1.Nodes;
for (int i = 0; i <= max_row; i++)
            {
                string combination = Convert.ToString(FinalDT.Rows[i]["tag_name"]);
                string[] data = combination.Split('.');


                TreeNodeCollection nodes = TV_TagList.Nodes;
                foreach (string name in data)
                {
                    if (nodes.ContainsKey(name))
                    {
                        node = nodes[name];
                    }
                    else
                    {
                        node = new TreeNode(name);
                        node.Name = name;
                        nodes.Add(node);
                    }
                    nodes = node.Nodes;
                }
            }

Same works for windows application but not for web application.
the mentioned for loop code works fine at windows application end. the same logic when tried in asp.net, containskey property is not part of Treenodecollection hence the logic fails. I need help to find out an alternate way to populate tree view using above mentioned example as input from datatable
Kindly help to get this resolved.
Posted
Updated 20-Oct-22 22:27pm
v8
Comments
Richard MacCutchan 21-Oct-22 3:13am    
Please use the Improve question link above, and add complete details of what is not working.
Member 12694392 21-Oct-22 4:09am    
the mentioned for loop code works fine at windows application end. the same logic when tried in asp.net, containskey property is not part of Treenodecollection hence the logic fails.
I need help to find out an alternate way to populate tree view using above mentioned example as input from datatable
Richard MacCutchan 21-Oct-22 5:15am    
Then you should check the documentation for the control, to see which properties are available to use.
Member 12694392 21-Oct-22 5:38am    
Thanks for the response, had already checked and also build logic accordingly but did not help. Referral code below

int max_row = Convert.ToInt32(FinalDT.Rows.Count);


foreach (DataRow row in FinalDT.Rows)
{
string tagName = Convert.ToString(row["tag_name"]);
string[] parts = tagName.Split('.');
TreeNodeCollection nodes = TV_TagList.Nodes;
for (int i = 0; i < parts.Length; i++)
{
string valuePath = string.Join(".", parts, 0, i);
TreeNode node = TV_TagList.FindNode(valuePath);
if (node == null)
{
node = new TreeNode(parts[i]);
nodes.Add(node);
}

nodes = node.ChildNodes;
}
}

I not getting unique data in mention logic above. stuck at this place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900