Firing events when selection changes between tree ctrl's 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
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

Firing events when selection changes between tree ctrl's

Post by Vexator »

i have several tree ctrl's in my app, but i am using only one function to handle events for all of them, like this:

Code: Select all

Connect( wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler(PropertiesPanel::OnSelectionChanged), 0, Properties );
As you can see, Properties is an instance of class PropertiesPanel and Properties->OnSelectionChanged is executed when the selection in any of the tree ctrl's is changed.

this works pretty fine so far, the only problem occurs if the user selects an item in one tree and then selects an item in another one. because in this case, no wxEVT_COMMAND_TREE_SEL_CHANGED event is fired. it is only fired if the selection changes in the SAME tree. so what i need now is an event that gets fired whenever selections change, not only selections from item #1 to item #2 in the same tree, but also from item #1 in tree #1 to item#1 in tree #2.

i hope this was not too confusing :P any ideas how i could manage this? thanks in advance! this is really urgent to me :(
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

Well, then I think you need to connect with tree->GetId() instead of wxID_ANY.
You might also need to use 2 Different Handlermethods, but it
should also work with the same method.
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

Post by Vexator »

thanks for the quick reply! just tried that, didn't change anything though :/
You might also need to use 2 Different Handlermethods
i want to have only one event handler to keep it flexible.. this way i can add as many trees with as many items as i want without having to modify my propertiespanel class.
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

Post by Vexator »

ok i found a simple workaround..

Code: Select all

void TreeControl::OnMouse( wxMouseEvent &event )
{
if( event.LeftDown() )
SelectItem( GetSelection() );

event.Skip();
}
this forces my tree ctrl's to fire a wxEVT_COMMAND_TREE_SEL_CHANGED event every time the left mouse button is clicked, then the event is skipped and so handled as usual. not very pretty though. if someone has a better idea, don't hesitate :)
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3
micros
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Sat Mar 18, 2006 10:41 am
Location: Ustek, Bohemia

Post by micros »

Try handling wxFocusEvent. When you click an item in tree1, it gains focus. When you then click into tree2, tree1 loses focus and tree2 gains it. For your case, it should be sufficient to handle only EVT_SET_FOCUS.
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

Post by Vexator »

yep you're right, works :) thank you!
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3
Post Reply