Naim

Naim

  • NA
  • 1
  • 0

Referencing objects from indexers

Feb 10 2007 12:13 AM
My primary language is C++, so learning C# while I'm attempting to write an app is sort of hard, while I suppose it's also giving me more experience.

Anyway, I'm attempting to build a tree of 'TreeNode' objects for a 'TreeView' control, from a tree of other objects, and I'm having trouble with references and indexers.



public TreeNode constructNode(ref ToDoGroup group)
{
TreeNode node = new TreeNode();
node.Text = group.m_name;
// TODO
// save a reference to the group into the TreeNode here

// TODO

// load the todo items into the node
for(int i = 0; i < group.m_todoItemList.Count; ++i)
{
TreeNode n = new TreeNode();

n.Text = group.m_todoItemList[i].m_name;
// TODO
// save reference to todoItem into TreeNode here
//n.Tag = ref group.m_todoItemList[i];
// TODO

// add the node to it's parent node
node.Nodes.Add(n);
}

// load the todo groups into the node
for (int i=0; i < group.m_todoGroupList.Count; ++i)
{
// construct the subtree of nodes
TreeNode n = constructNode(ref group.m_todoGroupList[i]);

// add the new subtree of nodes to it's parent
node.Nodes.Add(n);
}

return node;

}// function constructNode



I haven't figured out the code tags for this forum yet, so I hope it is readable.

Basically, I need to get a reference from the object, when the two lists 'm_todoGroupList' and 'm_todoItemList' are 'ArrayList' objects, and I found out that I can't get an object reference from indexing an ArrayList object, and I can't do it when using a 'foreach' statement.

The other tree (the one containing all the data) will be made up of 'ToDoGroup' items as nodes in the tree, and the children can be either a 'ToDoGroup' node or a 'ToDoItem' node (which can't have any children.

How can I do this? My intention is that whenever the other list is changed, the TreeView list (or at least the subtree that was changed) will be updated.

Should I be looking at a different method?