Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. traversing through a treeview web control

traversing through a treeview web control

Scheduled Pinned Locked Moved ASP.NET
designdata-structures
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kapil Thakur
    wrote on last edited by
    #1

    i want to traverse through a treeview web control and fetch the ID's of all checked nodes. that is, all those nodes whose checkboxes are checked in a treeview.i want to get their Id's. i've used the following code : ''' For getting selected contact id's from the Group Tree Function GetContacts() As ArrayList Dim mnode As Microsoft.Web.UI.WebControls.TreeNode Dim contacts As New ArrayList Viewstate("ContactCounter") = 0 For Each mnode In TV_MasterContactList.Nodes GetSelectedContactID(mnode.GetNodeIndex, contacts) Next Return contacts End Function Sub GetSelectedContactID(ByVal Tnode As String, ByRef Contacts As ArrayList) Dim nnode As Microsoft.Web.UI.WebControls.TreeNode If TV_MasterContactList.GetNodeFromIndex(Tnode).Type = "Contact" And TV_MasterContactList.GetNodeFromIndex(Tnode).Checked = True Then Contacts.Add(TV_MasterContactList.GetNodeFromIndex(Tnode).ID) End If For Each nnode In TV_MasterContactList.GetNodeFromIndex(Tnode).Nodes GetSelectedContactID(nnode.GetNodeIndex(), Contacts) Next End Sub but its not giving the correct result regards, Kapil

    M K 2 Replies Last reply
    0
    • K Kapil Thakur

      i want to traverse through a treeview web control and fetch the ID's of all checked nodes. that is, all those nodes whose checkboxes are checked in a treeview.i want to get their Id's. i've used the following code : ''' For getting selected contact id's from the Group Tree Function GetContacts() As ArrayList Dim mnode As Microsoft.Web.UI.WebControls.TreeNode Dim contacts As New ArrayList Viewstate("ContactCounter") = 0 For Each mnode In TV_MasterContactList.Nodes GetSelectedContactID(mnode.GetNodeIndex, contacts) Next Return contacts End Function Sub GetSelectedContactID(ByVal Tnode As String, ByRef Contacts As ArrayList) Dim nnode As Microsoft.Web.UI.WebControls.TreeNode If TV_MasterContactList.GetNodeFromIndex(Tnode).Type = "Contact" And TV_MasterContactList.GetNodeFromIndex(Tnode).Checked = True Then Contacts.Add(TV_MasterContactList.GetNodeFromIndex(Tnode).ID) End If For Each nnode In TV_MasterContactList.GetNodeFromIndex(Tnode).Nodes GetSelectedContactID(nnode.GetNodeIndex(), Contacts) Next End Sub but its not giving the correct result regards, Kapil

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      So what does it give you? Do you assign the ID value which you expect to receive to the ID property of the TreeNode?

      1 Reply Last reply
      0
      • K Kapil Thakur

        i want to traverse through a treeview web control and fetch the ID's of all checked nodes. that is, all those nodes whose checkboxes are checked in a treeview.i want to get their Id's. i've used the following code : ''' For getting selected contact id's from the Group Tree Function GetContacts() As ArrayList Dim mnode As Microsoft.Web.UI.WebControls.TreeNode Dim contacts As New ArrayList Viewstate("ContactCounter") = 0 For Each mnode In TV_MasterContactList.Nodes GetSelectedContactID(mnode.GetNodeIndex, contacts) Next Return contacts End Function Sub GetSelectedContactID(ByVal Tnode As String, ByRef Contacts As ArrayList) Dim nnode As Microsoft.Web.UI.WebControls.TreeNode If TV_MasterContactList.GetNodeFromIndex(Tnode).Type = "Contact" And TV_MasterContactList.GetNodeFromIndex(Tnode).Checked = True Then Contacts.Add(TV_MasterContactList.GetNodeFromIndex(Tnode).ID) End If For Each nnode In TV_MasterContactList.GetNodeFromIndex(Tnode).Nodes GetSelectedContactID(nnode.GetNodeIndex(), Contacts) Next End Sub but its not giving the correct result regards, Kapil

        K Offline
        K Offline
        Kapil Thakur
        wrote on last edited by
        #3

        when i check some checkboxes and on button click call these functions to retrieve the checked checkboxes Id. it shows even the checked checkboxes as unchecked and thus doesnt returns any Id's

        M 1 Reply Last reply
        0
        • K Kapil Thakur

          when i check some checkboxes and on button click call these functions to retrieve the checked checkboxes Id. it shows even the checked checkboxes as unchecked and thus doesnt returns any Id's

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          You might want to debug your application and try to step through your sample code line by line. Also, i'm curious that why you don't just use the TreeNode instance from the Nodes collection instead of using the GetNodeFromIndex method. Anyway, below is a quick example for this:

          private ArrayList GetContacts()
          ArrayList Contacts = new ArrayList();

          foreach(TreeNode node in TV\_MasterContactList.Nodes)
          {
          	GetSelectedContactID(node, Contacts);
          }
                    
          return  Contacts;			
          

          }

          private void GetSelectedContactID(TreeNode node, ArrayList Contacts)
          {
          if(node.Checked)
          Contacts.Add(node.ID);

          foreach(TreeNode child in node.Nodes)
          {
          	GetSelectedContactID(child, Contacts);	
          }
          

          }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups