Board index » cppbuilder » TTreeView add nodes

TTreeView add nodes


2003-10-23 10:28:14 PM
cppbuilder98
I'm using this:
void __fastcall TFrame3::FillChildren(TTreeNode* child, _di_IXMLNode node)
{
for (int i=0; i<node->GetChildNodes()->GetCount(); i++) {
_di_IXMLNode xnode = node->ChildNodes[0].Get(i);
TTreeNode* tnode = tvNodes->Items->Add(child, xnode->GetNodeName());
FillChildren(tnode, xnode);
}
}
//--------------------------------------------------------------------------
-
void __fastcall TFrame3::Fill(String cFileName)
{
tvNodes->Items->Clear();
xmlDoc->LoadFromFile(WideString(cFileName));
for (int i=0; i<xmlDoc->DocumentElement->GetChildNodes()->GetCount(); i++)
{
_di_IXMLNode xnode = xmlDoc->DocumentElement->ChildNodes[0].Get(i);
TTreeNode* tnode = tvNodes->Items->Add(NULL, xnode->GetNodeName());
FillChildren(tnode, xnode);
}
}
but it add nodes only as the root, not as children.
 
 

Re:TTreeView add nodes

I got it. instead of Add() should be AddChild().
 

Re:TTreeView add nodes

"Oliver Young" <none>wrote in message
Quote
for (int i=0; i<node->GetChildNodes()->GetCount(); i++) {
You shouldn't access the getter functions directly. Use the properties
instead:
for(int i = 0; i < node->ChildNodes->Count; ++i)
Quote
_di_IXMLNode xnode = node->ChildNodes[0].Get(i);
In C++, you cannot use the [] subscript operator on the ChildNodes property
itself like you can in Delphi. You need to use the Nodes subproperty
instead:
_di_IXMLNode xnode = node->ChildNodes->Nodes[i];
Quote
TTreeNode* tnode = tvNodes->Items->Add(child, xnode->GetNodeName());
Again, use a property instead of the getter function directly:
TTreeNode* tnode = tvNodes->Items->Add(child, xnode->NodeName);
Quote
xmlDoc->LoadFromFile(WideString(cFileName));
No need to cast. LoadFromFile() takes a WideString, which has an AnsiString
constructor and can perform the necessary conversion implicitially:
xmlDoc->LoadFromFile(cFileName);
Quote
for (int i=0; i<xmlDoc->DocumentElement->GetChildNodes()->GetCount();
i++)
Again, use properties:
for(int i = 0; i < xmlDoc->DocumentElement->ChildNodes->Count; ++i)
Alternatively, since you are basically repeating the same code that
FillChildren() already performs, you could just call FillChildren() instead:
FillChildren(NULL, xmlDoc->DocumentElement);
Gambit
 

{smallsort}