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. Other Discussions
  3. Clever Code
  4. Embedding Collection Controls (Or Any Object) in the TAG Property of Treeview. [modified]

Embedding Collection Controls (Or Any Object) in the TAG Property of Treeview. [modified]

Scheduled Pinned Locked Moved Clever Code
csharpvisual-studiodata-structureshelpannouncement
9 Posts 9 Posters 21 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.
  • N Offline
    N Offline
    Nobia
    wrote on last edited by
    #1

    I have accidentally discovered something in Visual Studio that (right now) is blowing my mind. I don't know if this is new or old news but it will change how I use Nodes in TreeView and Listview. I would like to hear back on what the community thinks about it. The code included is just test code to illustrate the principle. it is simple so you can experiment with it yourself. It doesn't actually do anything and you need to set breakpoints and check values to see results.

    Background

    Okay. I was playing around with writing my own Newsreader program. Many of the versions out there use TREEVIEW and COLLECTIONS of some type to save the data in. One for a GROUP which holds data for each newsgroup. Then a object collect which holds all the groups. They do similar structures for Articles and groups of articles. I had some trouble getting mine to work. I was using the TAG property of the tree node to hold formatted string data when I accidentally set a TAG to the entire newsgroup collection. I DID NOT GET AN ERROR. Whoa. In short I discovered that the TAG property of a TREEVIEW control can hold an object --- ANY OBJECT ---! Since what I wanted to do was have one node per newsgroup and show headers as subtree nodes - I stored the Newsgroup Collection in the node's TAG property. And it works. I do not need to find the collection and figure out which node to put it in or to find its elements. It in the Node! As a matter of fact the collection stored as a TREEVIEW (thats right - a treeview control that is not placed on a form but is placed inside the TAG property as an object). If I want to fill the sub tree I just iterate the sub nodes from the TAG property into Child Nodes. SIMPLE! And if I change a node inside the TAG Property it updates The Nodes automatically. I do not have to go find it! I really have not had time to explore all the possibilities yet and I am so excited about what i found that I write this (Sloppily) to share what I have found. I will make a better article after so more research. If this is already common knowledge then I'll be heart broken, but I could not find other references to this yet.

    Using the Code

    To play with the code use copy and paste in Visual Studio. * 1. Just create a new project and create an _'Explorer Form"_ from the add items Wizard. * 2. Replace all the code in the "LoadTree()" method of the form * 3. Place Breakpoints where ever you want (End SUB is good start). * 4. Set the Explorer form to be startup form.

    P D N R 4 Replies Last reply
    0
    • N Nobia

      I have accidentally discovered something in Visual Studio that (right now) is blowing my mind. I don't know if this is new or old news but it will change how I use Nodes in TreeView and Listview. I would like to hear back on what the community thinks about it. The code included is just test code to illustrate the principle. it is simple so you can experiment with it yourself. It doesn't actually do anything and you need to set breakpoints and check values to see results.

      Background

      Okay. I was playing around with writing my own Newsreader program. Many of the versions out there use TREEVIEW and COLLECTIONS of some type to save the data in. One for a GROUP which holds data for each newsgroup. Then a object collect which holds all the groups. They do similar structures for Articles and groups of articles. I had some trouble getting mine to work. I was using the TAG property of the tree node to hold formatted string data when I accidentally set a TAG to the entire newsgroup collection. I DID NOT GET AN ERROR. Whoa. In short I discovered that the TAG property of a TREEVIEW control can hold an object --- ANY OBJECT ---! Since what I wanted to do was have one node per newsgroup and show headers as subtree nodes - I stored the Newsgroup Collection in the node's TAG property. And it works. I do not need to find the collection and figure out which node to put it in or to find its elements. It in the Node! As a matter of fact the collection stored as a TREEVIEW (thats right - a treeview control that is not placed on a form but is placed inside the TAG property as an object). If I want to fill the sub tree I just iterate the sub nodes from the TAG property into Child Nodes. SIMPLE! And if I change a node inside the TAG Property it updates The Nodes automatically. I do not have to go find it! I really have not had time to explore all the possibilities yet and I am so excited about what i found that I write this (Sloppily) to share what I have found. I will make a better article after so more research. If this is already common knowledge then I'll be heart broken, but I could not find other references to this yet.

      Using the Code

      To play with the code use copy and paste in Visual Studio. * 1. Just create a new project and create an _'Explorer Form"_ from the add items Wizard. * 2. Replace all the code in the "LoadTree()" method of the form * 3. Place Breakpoints where ever you want (End SUB is good start). * 4. Set the Explorer form to be startup form.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      What's it doing here? If this is an article, submit it as an article; but I think it's more of a blog entry.

      1 Reply Last reply
      0
      • N Nobia

        I have accidentally discovered something in Visual Studio that (right now) is blowing my mind. I don't know if this is new or old news but it will change how I use Nodes in TreeView and Listview. I would like to hear back on what the community thinks about it. The code included is just test code to illustrate the principle. it is simple so you can experiment with it yourself. It doesn't actually do anything and you need to set breakpoints and check values to see results.

        Background

        Okay. I was playing around with writing my own Newsreader program. Many of the versions out there use TREEVIEW and COLLECTIONS of some type to save the data in. One for a GROUP which holds data for each newsgroup. Then a object collect which holds all the groups. They do similar structures for Articles and groups of articles. I had some trouble getting mine to work. I was using the TAG property of the tree node to hold formatted string data when I accidentally set a TAG to the entire newsgroup collection. I DID NOT GET AN ERROR. Whoa. In short I discovered that the TAG property of a TREEVIEW control can hold an object --- ANY OBJECT ---! Since what I wanted to do was have one node per newsgroup and show headers as subtree nodes - I stored the Newsgroup Collection in the node's TAG property. And it works. I do not need to find the collection and figure out which node to put it in or to find its elements. It in the Node! As a matter of fact the collection stored as a TREEVIEW (thats right - a treeview control that is not placed on a form but is placed inside the TAG property as an object). If I want to fill the sub tree I just iterate the sub nodes from the TAG property into Child Nodes. SIMPLE! And if I change a node inside the TAG Property it updates The Nodes automatically. I do not have to go find it! I really have not had time to explore all the possibilities yet and I am so excited about what i found that I write this (Sloppily) to share what I have found. I will make a better article after so more research. If this is already common knowledge then I'll be heart broken, but I could not find other references to this yet.

        Using the Code

        To play with the code use copy and paste in Visual Studio. * 1. Just create a new project and create an _'Explorer Form"_ from the add items Wizard. * 2. Replace all the code in the "LoadTree()" method of the form * 3. Place Breakpoints where ever you want (End SUB is good start). * 4. Set the Explorer form to be startup form.

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        Sorry, Its nothing new if you read the specification on the Tag property it is defined as; Public Property Tag as Object So you can hold anything you want in it. This isn't limited to Teeview or List's, it applicable to any control that inherits from the class Control. I have found many ways over the years of using the Tag to temporarily hold info....... For example, i have used Treeviews in the past where each level of tree holds a different type of object related to its parent. I have used the Tag to identify what type of information is held at that level, so when the user clicks/select that particular node level, an associated panel can display the correct panel containing the relevant information, it knows which panel by checking the nodes tag element, and then goes off and does whatever it needs to do. You can also use the Tag to hold a copy of the Node, so that you can undo before a save etc.

        Dave Who am I?: http://www.bebo.com/daveauld/ or http://www.dave-auld.net/

        L 1 Reply Last reply
        0
        • N Nobia

          I have accidentally discovered something in Visual Studio that (right now) is blowing my mind. I don't know if this is new or old news but it will change how I use Nodes in TreeView and Listview. I would like to hear back on what the community thinks about it. The code included is just test code to illustrate the principle. it is simple so you can experiment with it yourself. It doesn't actually do anything and you need to set breakpoints and check values to see results.

          Background

          Okay. I was playing around with writing my own Newsreader program. Many of the versions out there use TREEVIEW and COLLECTIONS of some type to save the data in. One for a GROUP which holds data for each newsgroup. Then a object collect which holds all the groups. They do similar structures for Articles and groups of articles. I had some trouble getting mine to work. I was using the TAG property of the tree node to hold formatted string data when I accidentally set a TAG to the entire newsgroup collection. I DID NOT GET AN ERROR. Whoa. In short I discovered that the TAG property of a TREEVIEW control can hold an object --- ANY OBJECT ---! Since what I wanted to do was have one node per newsgroup and show headers as subtree nodes - I stored the Newsgroup Collection in the node's TAG property. And it works. I do not need to find the collection and figure out which node to put it in or to find its elements. It in the Node! As a matter of fact the collection stored as a TREEVIEW (thats right - a treeview control that is not placed on a form but is placed inside the TAG property as an object). If I want to fill the sub tree I just iterate the sub nodes from the TAG property into Child Nodes. SIMPLE! And if I change a node inside the TAG Property it updates The Nodes automatically. I do not have to go find it! I really have not had time to explore all the possibilities yet and I am so excited about what i found that I write this (Sloppily) to share what I have found. I will make a better article after so more research. If this is already common knowledge then I'll be heart broken, but I could not find other references to this yet.

          Using the Code

          To play with the code use copy and paste in Visual Studio. * 1. Just create a new project and create an _'Explorer Form"_ from the add items Wizard. * 2. Replace all the code in the "LoadTree()" method of the form * 3. Place Breakpoints where ever you want (End SUB is good start). * 4. Set the Explorer form to be startup form.

          N Offline
          N Offline
          Nougat H
          wrote on last edited by
          #4

          I've expanded this forum to include not just subtle bugs, but any small code snippets that showcase truly excellent code. Something complicated, elegant, subtle - something that got you the hot date with the cute developer down the hall. Anything that you think others will enjoy and appreciate, like a complex wine.

          I would say this is more like sewage water than a good wine. X|

          ____________________________ I didn't know what to put in here.

          D 1 Reply Last reply
          0
          • N Nobia

            I have accidentally discovered something in Visual Studio that (right now) is blowing my mind. I don't know if this is new or old news but it will change how I use Nodes in TreeView and Listview. I would like to hear back on what the community thinks about it. The code included is just test code to illustrate the principle. it is simple so you can experiment with it yourself. It doesn't actually do anything and you need to set breakpoints and check values to see results.

            Background

            Okay. I was playing around with writing my own Newsreader program. Many of the versions out there use TREEVIEW and COLLECTIONS of some type to save the data in. One for a GROUP which holds data for each newsgroup. Then a object collect which holds all the groups. They do similar structures for Articles and groups of articles. I had some trouble getting mine to work. I was using the TAG property of the tree node to hold formatted string data when I accidentally set a TAG to the entire newsgroup collection. I DID NOT GET AN ERROR. Whoa. In short I discovered that the TAG property of a TREEVIEW control can hold an object --- ANY OBJECT ---! Since what I wanted to do was have one node per newsgroup and show headers as subtree nodes - I stored the Newsgroup Collection in the node's TAG property. And it works. I do not need to find the collection and figure out which node to put it in or to find its elements. It in the Node! As a matter of fact the collection stored as a TREEVIEW (thats right - a treeview control that is not placed on a form but is placed inside the TAG property as an object). If I want to fill the sub tree I just iterate the sub nodes from the TAG property into Child Nodes. SIMPLE! And if I change a node inside the TAG Property it updates The Nodes automatically. I do not have to go find it! I really have not had time to explore all the possibilities yet and I am so excited about what i found that I write this (Sloppily) to share what I have found. I will make a better article after so more research. If this is already common knowledge then I'll be heart broken, but I could not find other references to this yet.

            Using the Code

            To play with the code use copy and paste in Visual Studio. * 1. Just create a new project and create an _'Explorer Form"_ from the add items Wizard. * 2. Replace all the code in the "LoadTree()" method of the form * 3. Place Breakpoints where ever you want (End SUB is good start). * 4. Set the Explorer form to be startup form.

            R Offline
            R Offline
            Rob Smiley
            wrote on last edited by
            #5

            Ok, this isn't exactly revolutionary is it. Another (and IMHO better) way is to create a new class that inherits from TreeNode, then create field members in the subclass to store your data. That way, it's strongly typed & much clearer. Do you always comment every single line of you're code?

            "An eye for an eye only ends up making the whole world blind"

            N 1 Reply Last reply
            0
            • R Rob Smiley

              Ok, this isn't exactly revolutionary is it. Another (and IMHO better) way is to create a new class that inherits from TreeNode, then create field members in the subclass to store your data. That way, it's strongly typed & much clearer. Do you always comment every single line of you're code?

              "An eye for an eye only ends up making the whole world blind"

              N Offline
              N Offline
              NormDroid
              wrote on last edited by
              #6

              Rob Smiley wrote:

              Do you always comment every single line of you're code?

              Sign of a newbie or very unsure coder.

              Software Kinetics (requires SL3 beta) - Moving software

              1 Reply Last reply
              0
              • D DaveAuld

                Sorry, Its nothing new if you read the specification on the Tag property it is defined as; Public Property Tag as Object So you can hold anything you want in it. This isn't limited to Teeview or List's, it applicable to any control that inherits from the class Control. I have found many ways over the years of using the Tag to temporarily hold info....... For example, i have used Treeviews in the past where each level of tree holds a different type of object related to its parent. I have used the Tag to identify what type of information is held at that level, so when the user clicks/select that particular node level, an associated panel can display the correct panel containing the relevant information, it knows which panel by checking the nodes tag element, and then goes off and does whatever it needs to do. You can also use the Tag to hold a copy of the Node, so that you can undo before a save etc.

                Dave Who am I?: http://www.bebo.com/daveauld/ or http://www.dave-auld.net/

                L Offline
                L Offline
                livanCreep
                wrote on last edited by
                #7

                bahasa indonesia ya betul saya juga menggunakan tag itu untuk mempercepat proses dalam program saya, misalkan dalam kasus datagrid setiap satu baris menggambarkan satu class salesDetail yang setiap perubahan pada kolom ke 2 nya akan merubah qty nya (salesDetail.qty) agar lebih mudah saya tagkan class salesDetail itu kedalam datagridviewrow dim aRow as datagridviewrow arow = dgv.rows(dgv.rows.add()) . . . . arow.tag = aDetail mudah-mudahan anda mengerti

                D 1 Reply Last reply
                0
                • L livanCreep

                  bahasa indonesia ya betul saya juga menggunakan tag itu untuk mempercepat proses dalam program saya, misalkan dalam kasus datagrid setiap satu baris menggambarkan satu class salesDetail yang setiap perubahan pada kolom ke 2 nya akan merubah qty nya (salesDetail.qty) agar lebih mudah saya tagkan class salesDetail itu kedalam datagridviewrow dim aRow as datagridviewrow arow = dgv.rows(dgv.rows.add()) . . . . arow.tag = aDetail mudah-mudahan anda mengerti

                  D Offline
                  D Offline
                  darkelv
                  wrote on last edited by
                  #8

                  Though it serves not much of purpose posting in Bahasa in a community who mainly speak English and not understanding Bahasa, I guess this doesn't deserve 1 still. You could paste it and translate it using translate.google. Also, you can get the object back from .DataBoundItem, not necessary to tag it to DataGridViewRow

                  1 Reply Last reply
                  0
                  • N Nougat H

                    I've expanded this forum to include not just subtle bugs, but any small code snippets that showcase truly excellent code. Something complicated, elegant, subtle - something that got you the hot date with the cute developer down the hall. Anything that you think others will enjoy and appreciate, like a complex wine.

                    I would say this is more like sewage water than a good wine. X|

                    ____________________________ I didn't know what to put in here.

                    D Offline
                    D Offline
                    dojohansen
                    wrote on last edited by
                    #9

                    In related news: If you declare a field to be of type object, it can refer to ANY OBJECT! I mean, REALLY ANY OBJECT!!! THIS IS BLOWING MY MIND!!!!!! Off to write an article about the power of object...

                    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