Searching for TreeNode properties using C ++

0
Good afternoon. I'm trying to work with TreeNode s, I'd like to do a search based on the MyText properties, but I'm not getting the expected result.

What I wanted to appear to me was just the part that says Album1 (which is my text property). I also leave below my respective code. Do not call the conditions in my if because it was just another attempt to get the intended. What the conditions do is only to show Album1 , but not the nodes that are inside.

void FindRecursive2(TreeNode ^treeNode)
{
    System::Collections::IEnumerator^ myNodes = (safe_cast<System::Collections::IEnumerable^>(treeNode->Nodes))->GetEnumerator();
    while (myNodes->MoveNext())
    {
        // Responsável pela caixa de texto na imagem postada.
        System::Windows::Forms::DialogResult result = MessageBox::Show(this, myNodes->Current->ToString());

        if (treeNode->Text->ToString() == textBox4->Text || treeNode->Text->ToString() == textBox5->Text || treeNode->Text->ToString() == textBox6->Text)
            treeNode->BackColor = System::Drawing::Color::ForestGreen;
        TreeNode^ v2 = safe_cast<TreeNode^>(myNodes->Current);
        FindRecursive2(v2);
    }
}
    
asked by anonymous 25.06.2016 / 21:05

1 answer

1

Try to do this:

void FindRecursive2(TreeNode ^treeNode)
{
    System::Collections::IEnumerator^ myNodes = (safe_cast<System::Collections::IEnumerable^>(treeNode->Nodes))->GetEnumerator();
    while (myNodes->MoveNext())
    {
        TreeNode^ v2 = safe_cast<TreeNode^>(myNodes->Current);

        // Responsável pela caixa de texto na imagem postada.
        System::Windows::Forms::DialogResult result = MessageBox::Show(this, v2->Text->ToString());

        // Talvez neste if você queira usar v2->Text ao invés de treeNode->Text.
        if (treeNode->Text->ToString() == textBox4->Text || treeNode->Text->ToString() == textBox5->Text || treeNode->Text->ToString() == textBox6->Text) {
            treeNode->BackColor = System::Drawing::Color::ForestGreen;
        }

        FindRecursive2(v2);
    }
}
    
25.06.2016 / 21:56