updating treenode text dynamically
-
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
-
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
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.
-
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.
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?
-
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?
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.
-
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.
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.
-
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.
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.
-
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.
Yes, event triggered by tagged class is probably the best solution, but keeping a node list in tagged class is also good. thanks.
-
Yes, event triggered by tagged class is probably the best solution, but keeping a node list in tagged class is also good. thanks.
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