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. General Programming
  3. C#
  4. Keeping track of ID information with a TreeView

Keeping track of ID information with a TreeView

Scheduled Pinned Locked Moved C#
questiondatabasejsontutorial
3 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.
  • S Offline
    S Offline
    shultas
    wrote on last edited by
    #1

    Hello Everyone, Does anyone know of a way to populate a TreeView with information from a table in a database and keep track of the unique identifier for that record? I can't really explain it well in words, but there are reasons why I cannot do a "SELECT WHERE XXX = 'e.Node.Text'" (off of the TreeView_AfterSelect. What I did at one point was actually store the file id's inside the treeview, enclosed in [ ]'s and did parsing to figure out which FILE_ID it was, and then I could pull up the information that way, but it looks ugly. e.g. Parent | ------- Child [1] ------- Child [2] Where 1 and 2 are the unique key identifiers of that particular record in the database. I am just not sure how to go about linking a unique ID to every node in a TreeView without actually putting the ID right in the text for that particular node. I tried to populate an ArrayList with a structure that held the child's name and the ID for that child, and then iterate through the ArrayList when the treeview is clicked and find it ... but there can be duplicate entries in the database that have the same parent name and same child name. So basically the question is, when working with a TreeView and populating it from a database where the only thing that you can be sure is unique is the ID unique key ... How to do track that key with each node to ensure that when you click on a node you are pulling the proper record out of the database? Hopefully I made sense here. I rewrote this three times. I just can't really think of how to put this into words correctly.

    M 1 Reply Last reply
    0
    • S shultas

      Hello Everyone, Does anyone know of a way to populate a TreeView with information from a table in a database and keep track of the unique identifier for that record? I can't really explain it well in words, but there are reasons why I cannot do a "SELECT WHERE XXX = 'e.Node.Text'" (off of the TreeView_AfterSelect. What I did at one point was actually store the file id's inside the treeview, enclosed in [ ]'s and did parsing to figure out which FILE_ID it was, and then I could pull up the information that way, but it looks ugly. e.g. Parent | ------- Child [1] ------- Child [2] Where 1 and 2 are the unique key identifiers of that particular record in the database. I am just not sure how to go about linking a unique ID to every node in a TreeView without actually putting the ID right in the text for that particular node. I tried to populate an ArrayList with a structure that held the child's name and the ID for that child, and then iterate through the ArrayList when the treeview is clicked and find it ... but there can be duplicate entries in the database that have the same parent name and same child name. So basically the question is, when working with a TreeView and populating it from a database where the only thing that you can be sure is unique is the ID unique key ... How to do track that key with each node to ensure that when you click on a node you are pulling the proper record out of the database? Hopefully I made sense here. I rewrote this three times. I just can't really think of how to put this into words correctly.

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! Each TreeViewNode has a property named Tag. This way you can assign an arbitrary object to each tree node. Hope this helps.

      Regards, mav -- Black holes are the places where God divided by 0...

      S 1 Reply Last reply
      0
      • M mav northwind

        Hi! Each TreeViewNode has a property named Tag. This way you can assign an arbitrary object to each tree node. Hope this helps.

        Regards, mav -- Black holes are the places where God divided by 0...

        S Offline
        S Offline
        shultas
        wrote on last edited by
        #3

        Oh my! I read and read and read trying to find something like this. It is EXACTLY what I am looking for. I spent two days writing ArrayLists and all sorts of other stuff to try to keep track of the ID info! Thanks a bunch for the response!!!!

        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