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;
};