Treenode properties search using C++

Asked

Viewed 39 times

0

Good afternoon. I’m trying to work with TreeNodes, I would like to do a search based on the Text properties of my Name, 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 mind the conditions in my if because it was just another attempt to get the desired. What the conditions do is just show Album1, but not the nodes inside.

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

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);
    }
}
  • I don’t quite understand what you want, but I think that MessageBox::Show should or should be protected by a if, or be out of the while or just show up after a return or something similar.

  • The message box is just for me to test what is printed, I just wanted to print Album1. I don’t want the "treeNode to appear:"

1 answer

1


Try to do so:

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);
    }
}
  • Exactly, thank you very much. Incredible fire :)

  • @Great. I’m glad I could help you out. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.