treectrl unselect Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

treectrl unselect

Post by raananb »

How do I get a tree free of any selection?

I have a wxTreeCtrl defined with wxTR_SINGLE and wxTR_HIDE_ROOT. After an item is selected I try tree->Unselect() (within a right click event) but this fires a wxEVT_TREE_SEL_CHANGED event, automatically selecting the first item in the tree, which is not what I was looking for. If the first item is to be selected then this must be a user's choice.

In other words, how do I unselect a selected item?

The sample does not offer the option to unselect an item without selecting another item.

I tried using a 'clearSelection' variable to indicate that SelChange should not get involved, but the first item is still getting selected.

Code: Select all

void Interro::OnTREECTRLInterroCategoriesSelChanged( wxTreeEvent& WXUNUSED(event))
{
    if (clearSelection)
    {
        clearSelection = false;
        return;
    }

    selectedItem = tree_Categories->GetSelection();
}

void Interro::OnTREECTRLInterroCategoriesRightClick( wxTreeEvent& event)
{
    clearSelection = true;
    tree_Categories->Unselect();
}
(wxWidgets 3.1.4 & Windows 10)
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: treectrl unselect

Post by doublemax »

If i take the "treectrl" sample, remove the EVT_TREE_ITEM_MENU handler, enable the EVT_TREE_ITEM_RIGHT_CLICK handler, and just call "unselectAll()" in the event handler, it works for me.
Use the source, Luke!
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

Re: treectrl unselect

Post by raananb »

doublemax is right.

Note that my problem was not actually related to the code.

The problem only happens when Visual Studio debugger breakpoints are set at the beginning of each of the sequences of the code above.

When the breakpoints are removed, the code operates as expected.
Post Reply