troubleshooting Question

Populating TreeView in VB.Net

Avatar of pbissegger
pbisseggerFlag for Canada asked on
ASP.NETVisual Basic.NET
6 Comments3 Solutions762 ViewsLast Modified:
I am having a very difficult time finding anything that can help me populate a Treeview programmatically in VB.Net. Many articles use a "Set" which is no longer supported, or somehow don't address my simple needs.

Help !

Here is what I need

1. I have a 4 level list of a sports league:
     - 1st level : Leaguename
     - 2nd level: Team name
     - 3rd level: "Regular players" or "Spares"
     - 4th level : Player name

and I need name/value pairs stored in the tree

and I want to select the players using checkboxes

and I want to (on submit) get a list of the playerIDs which were selected.

2. I would like the code to look something like this:

      

' Add league node
myTreeView.Nodes.Add(New TreeNode(Leaguename, Session("Leaguenum")))


 ' Add teams
        cmd.CommandText = "select groupname, groupnum from leagues where leaguenum = " & Session("Leaguenum") & " and grouptype='Team' order by groupname"
        MyReader = cmd.ExecuteReader()
    
        Do While MyReader.Read()

        ' Add team mode
        myTreeView.Nodes(0).Nodes. Add(New TreeNode(Groupname, Groupnum))

        ' Add regular players
        cmd1.CommandText = "select l.groupnum as groupnum, c.lastname + ', ' + c.firstname as name, c.usernum as usernum from contacts c, leagues l where c.leaguenum = " & Session("Leaguenum") & " and l.groupnum = c.teamnum and playerstatus='regular'"
         MyReader1 = cmd1.ExecuteReader()  
        
        Do While MyReader1.Read()
    
        ' Add regular player node
        myTreeView.Nodes(0).Nodes(0).Nodes. Add(New TreeNode(name, usernum))
        
        Loop
    
        MyReader1.Close()
        
        ' Add spares
        cmd1.CommandText = "select l.groupnum as groupnum, c.lastname + ', ' + c.firstname as name, c.usernum as usernum from contacts c, leagues l where c.leaguenum = " & Session("Leaguenum") & " and l.groupnum = c.teamnum  and playerstatus='spare'"
        MyReader1 = cmd1.ExecuteReader()
    
        Do While MyReader1.Read()
    
       ' Add spare player node
        myTreeView.Nodes(0).Nodes(0).Nodes. Add(New TreeNode(name, usernum))
        Loop
    
        MyReader1.Close()

MyReader,Close()

with HTML code as:

 
<asp:TreeView ID="myTreeView" runat="server" ImageSet="Arrows" PathSeparator="|" ShowCheckBoxes="Leaf">
        <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
        <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />
        <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"  NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>

however the syntax I have for adding Nodes (and the Child nodes) is all wrong and I can't get it to work.

Help !
ASKER CERTIFIED SOLUTION
guvera

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros