Answer the question
In order to leave comments, you need to log in
How to bind class instances (or their properties) to TreeView nodes?
Friends, I ask you to suggest a solution to the problem:
There is a form, it has a TreeView, three TextBoxes and three Labels.
Text information is added to each selected node of the tree through textboxes (the nodes themselves and this information are added by pressing the buttons). Those. each node must store three string values somewhere in memory.
When a node is selected, this textual information should be displayed in three labels.
Question: how to implement it?
As I see the solution and where is the stupor: I create a class with the desired set of properties. When a node is added to the tree through a button, an instance of the class is created, its properties are filled with data from the textboxes and (here is a stupor) somehow you need to connect the node with a specific instance so that when selected, it refers to this specific instance and, accordingly, already from it to the label placed the necessary information.
Perhaps I am going the wrong way and this problem can be solved in a different way. For example, through the .Tag node property (if the array of text strings is stuffed there through a separator) or something else. But I feel that the solution is on the surface.
More interested not in specifics, but in the very principle of implementing such tasks. But if there are specifics, even better :)
Additionally, I’m interested in: if you still manage to bind an instance to a node, then when you delete the node, it turns out that there will be no access to the instance. How then not to litter the memory by accumulating these instances "hanging in obscurity"?
I will be glad for any answer: links to materials that you can read, practical examples, just ideas ... Everything.
Thank you.
Answer the question
In order to leave comments, you need to log in
Do it through the database.
Table with fields id, parent_id, node_name, text_info.
When a node is selected, a request is made by id and text_info is obtained.
To build a node, a bunch of id and parent_id is recursively used, there are many implementation options. Google, for example, this or that .
The database can be used with SQLite.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question