Original Post
I'm having a little bit of trouble with the 'Tag' field of a TreeNode. I have a heirarchy in a TreeView, which contains 2 types of nodes. ToDoGroups and ToDoItems. A have a tree of ToDoGroups (which can contain ToDoGroups and ToDoItems), where each node in the tree corresponds to 1 node in the TreeView. At the moment, when a TreeView node is clicked on, I am trying to load a bunch of data from the ToDo tree node that it is associated with. To connect the two associated nodes, in each TreeNode, I am storing a reference (I am assuming a reference, I just use the assignment operator), to the ToDo node in the Tag field of the TreeView TreeNode. The problem is that I need to load different things depending on which ToDo node type the Tree. How do I go about distinguishing the different types from each other? I've tried this:
if( ToDoList_heirarchy.SelectedNode.Tag.GetType() == ToDoList.ToDoItem ){
this.ToDoList_Notes_Textbox.Text = ((ToDoList.ToDoItem)ToDoList_heirarchy.SelectedNode.Tag).Text;
}
But the compiler complains that "'ToDoList.ToDoItem' is a 'type', which is not valid in the given context". What next? Should I be associating the TreeView and ToDo nodes in a different way?