This is a migrated thread and some comments may be shown as answers.

for each loop to display a treeview

3 Answers 129 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Marcos
Top achievements
Rank 1
Marcos asked on 14 Mar 2011, 09:07 PM
I'm pretty new at this so I don't know much about how to use this or the proper way to call things so I apologize if I don't explain it very well.
Use this picture for reference: http://i178.photobucket.com/albums/w270/marcoshid/Other/Ethernet_View.jpg

  I'm trying to make a treeview that will display the nodes '01', '02', etc one right under the other without the black node that is currently above the '02' node. Here is my code for it:


Eth_Rel ethernet_1 = new Eth_Rel();
       protected void Ethernet_Load(object sender, EventArgs e)
       {
           RadTreeNode aParent = new RadTreeNode();
 
           aParent.Text = "Ethernet Connection";
           using (MapTest.Model.Computer_InventoryEntities context = new Computer_InventoryEntities())
           {
               int _roomID = 10;
               var list = (from c in context.Eth_Rel where c.rm_id == _roomID select c).ToList();
               
               string temp=null;
               int id=999999;
              // string etherName = null;
               foreach ( Eth_Rel eth in list)
               {
                   RadTreeNode ethernet = new RadTreeNode();
                   RadTreeNode ethernet1 = new RadTreeNode();
                   RadTreeNode panel = new RadTreeNode();
                   RadTreeNode panel1 = new RadTreeNode();
                   if ((temp != eth.SocketReference.Value.sck_pnl))
                   {
                       
                       ethernet.Text = eth.Room.rm_code + " - " + eth.SocketReference.Value.sck_pnl;
                       panel.Text = "0" + eth.pnl_id.ToString();
 
                       RadTreeNode speed = new RadTreeNode();
                       speed.Text = "Speed: " + eth.SpeedReference.Value.spd_type;
                       panel.Nodes.Add(speed);
 
                       RadTreeNode connects = new RadTreeNode();
                       connects.Text = "Connects to: " + eth.ComputerReference.Value.comp_name;
                       panel.Nodes.Add(connects);
 
                       RadTreeNode location = new RadTreeNode();
                       location.Text = "Location: " + eth.LocationReference.Value.loc_name;
                       panel.Nodes.Add(location);
                       
                   }
                   if ((temp == eth.SocketReference.Value.sck_pnl && id != eth.pnl_id))
                   {
 
                       panel1.Text = "0" + eth.pnl_id.ToString();
 
                       RadTreeNode speed = new RadTreeNode();
                       speed.Text = "Speed: " + eth.SpeedReference.Value.spd_type;
                       panel1.Nodes.Add(speed);
 
                       RadTreeNode connects = new RadTreeNode();
                       connects.Text = "Connects to: " + eth.ComputerReference.Value.comp_name;
                       panel1.Nodes.Add(connects);
 
                       RadTreeNode location = new RadTreeNode();
                       location.Text = "Location: " + eth.LocationReference.Value.loc_name;
                       panel1.Nodes.Add(location);
                        
                   }
                   else
                   {
                      
                   }
                   ethernet.Nodes.Add(panel);
                   aParent.Nodes.Add(ethernet);
                   ethernet.Nodes.Add(panel1);
                   aParent.Nodes.Add(ethernet);
                   
                   temp = eth.SocketReference.Value.sck_pnl;
                   id = eth.pnl_id;
               }        
               
           }
           RadTreeView3.Nodes.Add(aParent);
       }



 


Thanks for the help in advance,
Marcos H.


3 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 17 Mar 2011, 02:41 PM
Hello Marcos,

From what you provided seems that the Eth_Rel sometimes doesn't poses Room.rm_code.
Which means that you need to check the data that you use to construct your TreeView.


Regards,
Nikolay Tsenkov
the Telerik team
0
Marcos
Top achievements
Rank 1
answered on 23 Mar 2011, 09:49 PM
I'm still new at this so I may have implemented it wrong. But from my understanding the reason Room.rm_code isn't always there is so that the same room code doesn't appear more than once. I've tried putting it inside the second if statement but that only repats the same thing twice within the same node. And what I want is for the Room.rm_code to not repeat itself but the contents that should be within it iterate like the two nodes within a certain Room.rm_code that are "01" and "02"  this would be the eth.pnl_id and for more data to be within each of those, eth.SpeedReference.Value.spd_type, eth.ComputerReference.Value.comp_name, and eth.LocationReference.Value.loc_name



Thanks for the assistance.
Marcos
0
Nikolay Tsenkov
Telerik team
answered on 28 Mar 2011, 04:21 PM
Hi Marcos,

If you set at least the roomId to all records, then you can check if the room is already created as a RadTreeNode (FindNodeByText for example) and if it exists - add directly to it, if not create a new one and add the branch to it instead.


Regards,
Nikolay Tsenkov
the Telerik team
Tags
TreeView
Asked by
Marcos
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Marcos
Top achievements
Rank 1
Share this question
or