scorpionguy
May 23rd, 2006, 08:15 PM
Hello,
I have this(and many other nodes) declaration for a node in the tree.
System::Windows::Forms::TreeNode* __mcTemp__3[] = new System::Windows::Forms::TreeNode*[3];
__mcTemp__3[0] = new System::Windows::Forms::TreeNode(S"Diploma");
The problem is if I try to access __mcTemp__3[0] node in say button click event it says undeclared identifier.. Does anyone know how to access a particular node of the tree in treeview
Thanks
ThermoSight
May 23rd, 2006, 11:14 PM
Scorpion,
did you see my note in the earlier thread ? If I understand your question here, you're asking about the procedure to access individual nodes in a tree view.
There are, or at least I **THINK** there are, a number of ways to do that ....
for instance, you can use property 'Nodes' to get the entire collection and then select the one or oneS you want from the collection via an index,
TreeNodeCollection *pNodes = treeView1->Nodes;
TreeNode *tn = pNodes->Item[23]; or alternatively, remove the intermediate step ....
pNodes->Item[ijk]->BackColor = Color::FromName(S"Bisque");
or you can use property 'SelectedNode' to get the node which is selected
(TreeNode *tn = treeView1->SelectedNode;)
or you can use property 'TopNode' to get the uppermost Node (
TreeNode *tn = treeView1->TopNode;)
or you can use method 'GetNodeAt' to get the Node at the specified location (usually as specified by mouse location). (treeView1->GetNodeAt(new Point(e->X, e->Y)) where 'e' refers to the MouseEventArgs pointer presented to the yourcontrolnamehere_MouseUp event handler)
or you can attach an event handler to the
"yourcontrolnamehere_afterSelect" event and use the TreeViewEventArgs class argument which maintains the details on the selected node:: (ie "e->Node->Text", for example)
Again, this is all spelled out for ya in the IDE Help section along with samples.
Another thing to consider:: if your items do indeed maintain a tree-like relationship, then the TreeView class is a good choice, but if they don't have that relationship and are merely a collection of items, then you might consider a different control ... a ListView perhaps.
I won't bug you again.
Best wishes,
bill