Problems with deselecting an Item in wxListCtrl

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
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Problems with deselecting an Item in wxListCtrl

Post by phlox81 »

Hi,

I have wxListCtrl in Iconmode, and need to deselect the item after its been selected.
The Programm is meant for a touchscreen device, so when you hit an item, it displays a dialog, and after the dialog returns, it should deselect the item.

My Code in the selection handler:

Code: Select all

void Frame::Onm_itemlistItemSelect(wxListEvent& event)
{
    int i = event.GetIndex();
	
	if( i >= 0 && i <= 5)
	{
        (this->*m_callmap[i]])();
		//event.Skip(false);
		m_itemlist->SetItemState(i, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
	}
}
This works, but the handler is then beeing called a second time, so that the dialog pops up twice.

So, how to solve this?
Last edited by phlox81 on Fri Dec 10, 2010 9:56 pm, edited 1 time in total.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

Are you saying that you get 2 Select events? That would be wrong, but it doesn't happen in the listctrl sample with 2.9

You probably checked this already but anyway: is by any chance the second one a Deselect event? Or check that you did not connect the event handler twice..
Does it also happen if you do not show the dialog?

In the worst case as a quick workaround you can put a flag (ignoreNextSelectEvent) that will be set to true by the first event and just unset by the second. Not perfect but should handle the described scenario.
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

Its only happening if I have the code for deselecting in, without it does not happen.

I'm using wx2.8.6/11. (have to).

I already tried static bool guard = true/false; but thats a hack and it really didn't work that well.
Post Reply