Code: Select all
Buffer.Append(ItemName);
do
{
if(text.Len()==0)
{
otherid = theTree->GetFirstChild(branch, cookie);
}
if(otherid.IsOk())
{
do
{
// valid
text = theTree->GetItemText(otherid);
if(Buffer.Cmp( text )== 0)
{
// We have a match!
OnNewRoot(otherid, ItemName, names, values, i);
return;
}
otherid = theTree->GetNextChild(branch, cookie);
}while(otherid.IsOk());
}
otherid = theTree->GetNextSibling(branch);
}while(otherid.IsOk());
OnNewRoot (theTree->GetRootItem(), ItemName, names, values, i);
ItemName = name of tree item
names = wxStringArray of subitems
values = wxStringArray of subitem values
i = number of subitems
What I want to have happen is for the function to search the tree for an instance of "ItemName" If it finds it I want the id stored in "otherid".
At this time it is not working properly as it will not find an "ItemName" if it is inside another tree and instead creates a new tree off of root!
So if my tree is:
Code: Select all
root
+Hardware // ItemName
+Hammer // names[0]
+qty // values[0]
Code: Select all
Hammer // ItemName
+Qty // names[0]
+5 //values[0]
+Color //names[1]
+Green //values[1]
just for reference:
Code: Select all
void OnNewRoot (const wxTreeItemId &node, char *ItemName, wxArrayString names, wxArrayString values, int i)
{
int x=0;
wxTreeItemId id;
wxTreeItemId kid = node;
wxString Buffer;
// Add department node
Buffer=theTree->GetItemText(node);
if(Buffer.Cmp( ItemName )!= 0)
{
kid = theTree->AppendItem(theTree->GetRootItem(),
ItemName,
-1,
-1,
NULL);
x=0;
}
theTree->DeleteChildren(kid);
do
{
// these are to be children!
theTree->AppendItem((theTree->AppendItem(kid,
names[x],
-1,
-1,
NULL)),
values[x],
-1,
-1,
NULL);
x++;
}while (x<i);
theTree->Expand(kid);
}
What I think is happening is that if a branch has multiple children with children of their own only the first child is searched as when it hits the end of that branch it goes back to the top level and looks for a new sibling... I'm guessing (real late, getting punchy) that I need to tell the searching function to back up and look for more children from the branch being searched before finding the next sibling of the branch being searched.