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. updating treenode text dynamically

updating treenode text dynamically

Scheduled Pinned Locked Moved C#
databasejsonquestionannouncement
8 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.
  • X Offline
    X Offline
    xilefxilef
    wrote on last edited by
    #1

    I have a treeview where many treenodes belonging to different parent nodes may represent the same object, so if a user updates a text for such node, it should also trigger an update of text for all other nodes representing the same object. For instance if I have nodes representing school classes (math, english...) each class node has student nodes with student name as text, so numerous classes can contain the nodes with same student name. If I change students name under one parent, it should update it under the rest. I would assign the student object to nodes tag, but how would I trigger a text update? thanks

    P 1 Reply Last reply
    0
    • X xilefxilef

      I have a treeview where many treenodes belonging to different parent nodes may represent the same object, so if a user updates a text for such node, it should also trigger an update of text for all other nodes representing the same object. For instance if I have nodes representing school classes (math, english...) each class node has student nodes with student name as text, so numerous classes can contain the nodes with same student name. If I change students name under one parent, it should update it under the rest. I would assign the student object to nodes tag, but how would I trigger a text update? thanks

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

      There are a number of ways. Ideally, the student class has a ToString or similar method that is used to format the text for the node. Then you can enumerate the nodes, updating the text. You can probably make that quicker by checking to see if it's the updated record. And you should probably do that on a thread.

      X 1 Reply Last reply
      0
      • P PIEBALDconsult

        There are a number of ways. Ideally, the student class has a ToString or similar method that is used to format the text for the node. Then you can enumerate the nodes, updating the text. You can probably make that quicker by checking to see if it's the updated record. And you should probably do that on a thread.

        X Offline
        X Offline
        xilefxilef
        wrote on last edited by
        #3

        I do not have a collection of other nodes that need to be updated, so cannot enumerate. This is a form treenode, not web, so there is no updateOnDemand property. I was thinking of doing this on text update - calling tag object method that in turn calls treenode's method to update the text. this way, a single node text update would trigger text update for all nodes tagging the same object. Is there a better way?

        P 1 Reply Last reply
        0
        • X xilefxilef

          I do not have a collection of other nodes that need to be updated, so cannot enumerate. This is a form treenode, not web, so there is no updateOnDemand property. I was thinking of doing this on text update - calling tag object method that in turn calls treenode's method to update the text. this way, a single node text update would trigger text update for all nodes tagging the same object. Is there a better way?

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

          xilefxilef wrote:

          I do not have a collection of other nodes

          The tree has a collection of all the nodes -- enumerate them, updating as necessary. You can use memory rather than CPU to maintain your own collections, but I'd start with the simple way first.

          X 1 Reply Last reply
          0
          • P PIEBALDconsult

            xilefxilef wrote:

            I do not have a collection of other nodes

            The tree has a collection of all the nodes -- enumerate them, updating as necessary. You can use memory rather than CPU to maintain your own collections, but I'd start with the simple way first.

            X Offline
            X Offline
            xilefxilef
            wrote on last edited by
            #5

            Right, it has all nodes, but this way I need to enumerate through all of them and find the ones I want to update. I was talking about an event that would trigger an update without having to enumerate through the whole tree. I would override TreeNode.Text property to point to tagged object's text property, but strings are immutable and if I change tagged object's text property, it would do nothing to nodes text.

            P 1 Reply Last reply
            0
            • X xilefxilef

              Right, it has all nodes, but this way I need to enumerate through all of them and find the ones I want to update. I was talking about an event that would trigger an update without having to enumerate through the whole tree. I would override TreeNode.Text property to point to tagged object's text property, but strings are immutable and if I change tagged object's text property, it would do nothing to nodes text.

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

              That would be good if it can be done, but I don't know that it can (or can't) be done. I was thinking of having the student class have an OnChanged event (or something) that a specialized TreeNode could hook onto. Failing that, you could have a class that associates a student with a bunch of nodes.

              X 1 Reply Last reply
              0
              • P PIEBALDconsult

                That would be good if it can be done, but I don't know that it can (or can't) be done. I was thinking of having the student class have an OnChanged event (or something) that a specialized TreeNode could hook onto. Failing that, you could have a class that associates a student with a bunch of nodes.

                X Offline
                X Offline
                xilefxilef
                wrote on last edited by
                #7

                Yes, event triggered by tagged class is probably the best solution, but keeping a node list in tagged class is also good. thanks.

                P 1 Reply Last reply
                0
                • X xilefxilef

                  Yes, event triggered by tagged class is probably the best solution, but keeping a node list in tagged class is also good. thanks.

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

                  xilefxilef wrote:

                  is also good.

                  It's just more memory-intensive, I'd prefer to try the CPU-intensive solution and then decide whether or not it provides good performance

                  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