So – working with C# and Windows Forms, I have a bunch of “Task” classes. Every class has a List<Task>, so that they can have any number of children (and the children can obviously have more children…)
These tasks are stored in a “Project” class (in a List<Task>, obviously), which is then serialized to XML. I have a function to recurse through the tasks and put them all in a TreeView. It works just like it should.
But the thing is – if I select a task from the TreeView, how will I find it from the Project? I thought of some kind of foreign key (which would be the TreeNode’s key?), but since I’m using XML for serialization, that’s not possible.
So, what should I do?
I would put a reference to the “Task” object in the Tag member of each TreeNode. It then becomes very easy to cast the Tag to a Task and use the Task when handling any Tree event.