Strange behavior with TreeView


#1

Hello Jules,
I have a problem with TreeView.
When I select/deselect an item with Ctrl+Click, the item is deselected in the mouseUp method but itemClicked() is only called in mouseDown(). It is a problem for me because I do something in itemClicked() which is in relation with the selected items.
So I have a question: Why don’t you call the itemClicked() method in mouseUp() in (as you have done in the TableListBox class). Is it volontary done or did you forget it?

I’ve tried to add the linesfrom mouseDown in mouseUp :

    void mouseUp (const MouseEvent& e)
    {
        Rectangle pos;
        TreeViewItem* const item = findItemAt (e.y, pos);

        if (item != 0 && e.mouseWasClicked())
        {
            if (needSelectionOnMouseUp)
            {
              selectBasedOnModifiers (item, e.mods);
              MouseEvent e2 (e);
              e2.x -= pos.getX();
              e2.y -= pos.getY();
              item->itemClicked (e2);

            }
.....

and it seems to work for me.

Kevin


#2

Well, it sounds like you’re asking the wrong question there - if you’re doing something based on the selection, then surely what you actually want is a selectionChanged() callback. There’s already a itemSelectionChanged() method - does that do the job?


#3

Thanks for your answer,
the itemSelectionChanged method seems to do what I want.

Kevin