Filtered wxListBox Problem with WxWidgets-3.1.1

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
User avatar
ggbutcher
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Aug 08, 2017 11:37 pm

Filtered wxListBox Problem with WxWidgets-3.1.1

Post by ggbutcher »

For completeness, I searched first, only found this thread:
viewtopic.php?f=1&t=19997&hilit=filtered+wxListBox

I subclassed wxListBox to do just this, filter the list based on a string, list pares down to just those entries that contain the string. It behaves fine in wxWidgets-3.1.0, but the listbox just stops working (no scroll, no select, no filter) when a space character is encountered in the filter string with wxWidgets-3.1.1. I reviewed the commits between the two versions, can't find anything pertinent. Here's the code:

Code: Select all

class myListCtrl: public wxListCtrl
{
	public:
		//Constructs the list control, populated with the items passed in the listitems wxArrayString:
		myListCtrl(wxWindow *parent, wxWindowID id, wxString listname, wxArrayString listitems, const wxPoint &pos=wxDefaultPositi
			wxListCtrl(parent, id, pos, size, wxLC_REPORT | wxLC_NO_HEADER | wxLC_HRULES, wxDefaultValidator, listname)
		{
			//SetDoubleBuffered(true);
			name = listname;
			width = size.x;
			wxListItem col0;
			col0.SetId(0);
			col0.SetText(name );
			col0.SetWidth(width);
			InsertColumn(0, col0);

			itemlist = listitems;

			for (int i=0; i<itemlist.GetCount(); i++) {
				wxListItem item;
				item.SetId(i);
				item.SetText( itemlist[i] );
				InsertItem( item );
			}

			filter = "";
			selected = "";

			Bind(wxEVT_LIST_ITEM_SELECTED, &myListCtrl::Selected, this);
		}

		//Filters the list to include only entries that contain the specified string:
		void setFilter(wxString f)
		{
			filter = f;
			DeleteAllItems();

			for (int i=0; i<itemlist.GetCount(); i++) {
				if (itemlist[i].Find(filter) != wxNOT_FOUND) {
					wxListItem item;
					item.SetId(j);
					item.SetText( itemlist[i] );
					InsertItem( item );
					j++;
					filteredlist.Add(itemlist[i]);
				}
			}
			Refresh();
		}

		//Captures the entry selected, at selection:
		void Selected(wxListEvent& event)
		{
			selected = event.GetText();
			event.Skip();
		}

		//Returns the selected entry, as populated by the wxListEvent method:
		wxString GetSelected()
		{
			return selected;
		}

	private:
		int width;
		wxArrayString itemlist;
		wxString filter, selected, name;
};
Insights would be much appreciated!
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Filtered wxListBox Problem with WxWidgets-3.1.1

Post by doublemax »

It behaves fine in wxWidgets-3.1.0, but the listbox just stops working (no scroll, no select, no filter) when a space character is encountered in the filter string with wxWidgets-3.1.1
I assume that you mean that the list is always empty after filtering? That would mean that wxString::Find is buggy, which i find very unlikely.

Can you try to narrow it down a bit more and check where exactly the problem occurs?

Edit: Just tested this in 3.1.1, works fine. Either the problem lies somewhere else or i misunderstood what the problem is.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Filtered wxListBox Problem with WxWidgets-3.1.1

Post by ONEEYEMAN »

Hi,
Can you do the git bisection to find the breaking commit?

More info here.

Git is great for that.

Thank you.
User avatar
ggbutcher
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Aug 08, 2017 11:37 pm

Re: Filtered wxListBox Problem with WxWidgets-3.1.1

Post by ggbutcher »

Well, came back home from work with the intent to duplicate the problem, and now I can't. I thought it'd be Win32 specific, but that seems to be working now, both wxWidgets-3.1.0 and 3.1.1.

Thanks for investigating, and enjoy the sub-class...!
Post Reply