TAdvTreeView - unable to find children using FindNodeByTextAndColumn

Hello,
i have a tree that looks like this:

Parent1
child1_1
child1_2
.......
Parent2
child2_1
child2_2
.........
This nodes are in the same Column (column 0).
Let's say Parent1,child1_1,... are the names of the nodes, if i try to find Parent1 using this instruction
n = Tree2->FindVirtualNodeByTextAndColumn("Parent1", 0, true, true);
i'm able to find the right node, but if i search for the child:
n = Tree2->FindVirtualNodeByTextAndColumn("child1_1", 0, true, true);
n is always NULL.
What i'm trying to obtain is to find a node knowing only its name and get its row.
Any suggestions? Thanks

With a default TAdvTreeView on the form, I'm able to find the node with the text RS5, with the FindVirtualNodeByTextAndColumn. Under which circumstances are you executing this? Do you do this when building the node structure?

Hello,
i'm not searching for the node when creating the Tree. The tree is already been created and i'm outside BeginUpdate() and EndUpdate() instructions. Here is a more accurate code that is closer to mine:

TAdvTreeViewNode *pn,*pn2,*nc,*nc2;
TStringList *Lst = new TStringList();
UnicodeString Title,S;
int i;
//cfg is a TMemIniFile; pn is the parent node, nc is the child node
for(i=1; iCount; i++)
{
Title = cfg->ReadString(Lst->Strings[i], "JohnDoe", "");
pn = FrmMain->Tree2->FindNodeByTextAndColumn(Title, 0, true, true); //here it works
if(pn == NULL)
{
Tree->BeginUpdate();
pn = Tree->AddNode();
pn->Text[0] = cfg->ReadString(Lst->Strings[i], "JohnDoe", "");
nc = Tree->AddNode(pn);
nc->Text[0] = Lst->Strings[i];
nc->Text[1] = "Something 1";
nc->Text[2] = "Something 2";
Tree->EndUpdate();
}
else
{
//do something else
}
}
//try to find last child node added
S = nc->Text[0];
pn2 = Tree->FindNodeByTextAndColumn(S, 0, true, true);

pn2 is NULL. Can't find it.
I also have done your test(default AdvTreeView and find "RS5" and it works). I suppose something is wrong when adding children

Hi,

The FindNodeByTextAndColumn uses a pattern search, so you need to add double quotes to search for strings that contain spaces. Adding double quotes to the S variable around your node text should fix the issue.

Thanks, now it works correctly

1 Like