Page 1 of 1

What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 1:55 pm
by Tapsa
And if I want my derived control to save selected items, how can I know that shift key was used to selected several items at once?
I assume that selection event has stored the selected index that I could use, but probably skipping items selected using shift key.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 6:06 pm
by doublemax
wxEVT_COMMAND_LISTBOX_SELECTED ~ wxEVT_LIST_ITEM_SELECTED

With wxListCtrl::GetSelectedItemCount() you get the total number of selected items.
With wxListCtrl::GetNextItem() you can get all selected items in a loop.
http://docs.wxwidgets.org/trunk/classwx ... 89caa32e78

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 6:24 pm
by Tapsa
Thanks. I got the next item code to work (though from an event hooked to wxListBox). I get
error: 'wxEVT_LIST_ITEM_SELECTED' was not declared in this scope
with the following code and I do have <wx/listctrl.h> included.

Code: Select all

Connect(Graphics_Graphics_ListV->GetId(), wxEVT_LIST_ITEM_SELECTED , wxListEventHandler(AGE_Frame::OnGraphicsSelect));
Can connect be used with wxListEvents?

It looks like wxWidgets 2.8 has wxEVT_COMMAND_LIST_ITEM_SELECTED.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 6:44 pm
by doublemax
It looks like wxWidgets 2.8 has wxEVT_COMMAND_LIST_ITEM_SELECTED.
If you're using 2.8 you have to use wxEVT_COMMAND_LIST_ITEM_SELECTED indeed.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 6:57 pm
by Tapsa
While that kinda solves my original question, that event doesn't catch selection changes when deselecting or when selecting many items with shift button down. I was looking for one event to rule them all. I guess I can write a wrapper that connects all the necessary events. During my short affair with Qt I faced the same problem and I had to connect the underlaying selection model, but it had selectionChanged event that covered all my use cases.

I also find it annoying that I can't select many items just by holding down left mouse button, like I can with wxListBox.
And I would like the column width to always be the width of the text control.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 8:03 pm
by doublemax
that event doesn't catch selection changes when deselecting or when selecting many items with shift button down.
I just tested this with the "listctrl" sample in 2.8.12 and 3.0.2. I always get Selection/Deselection events, even when the Shift-key was used to select multiple items.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 9:11 pm
by Tapsa
Did you treat it as a wxListEvent or wxCommandEvent? It looks like both can be applied and the result is same.
It's time for me to write some wrapper function then.

This is my simple list control class. Perhaps it's those style flags :?

Code: Select all

class AGEListView: public wxListCtrl
{
public:
    AGEListView(wxWindow *parent, const wxSize &size):
    wxListCtrl(parent, wxID_ANY, wxDefaultPosition, size, wxLC_VIRTUAL | wxLC_REPORT | wxLC_NO_HEADER)
    {
        SetItemCount(0);
        InsertColumn(0, wxEmptyString, wxLIST_FORMAT_LEFT, 200);
    }

    wxArrayString names;
    vector<int> indexes;

private:
    virtual wxString OnGetItemText(long item, long column) const;
};
Seeing that there are both EVT_LIST_ITEM_SELECTED and EVT_LIST_ITEM_DESELECTED macros and that the documentation doesn't have other selection event macros, I think EVT_LIST_ITEM_SELECTED is meant to only process basic left mouse button clicks that make an item selected. In short, there is no equivalent for wxEVT_COMMAND_LISTBOX_SELECTED in wxListCtrl.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sat Jun 27, 2015 9:32 pm
by doublemax
Yes, in virtual mode the situation is different. The only event you can use in this case is wxEVT_LIST_ITEM_FOCUSED.

Re: What is the wxListCtrl equivalent of wxEVT_COMMAND_LISTBOX_SELECTED?

Posted: Sun Jun 28, 2015 6:27 am
by Tapsa
Fantastic! :D It seems to fire exactly when I need it to. Not firing on mouse hover :)