pythonuser-interfacewxpythonwxformbuilder

wxPython | wxDataViewListCtrl get all selected rows/items


I`m using wxPython in conjunctions with wxFormBuilder. I have a wxDataViewListCtrl with 5 columns to list my values. The user can select one or more rows (style = wxDV_MULTIPLE). If the user only select one row i can catch it with this method:

def showContextTZM( self, event ):
    if self.m_dvlc.HasSelection():
        item_id = event.GetItem().GetID()

If the user selects more than one row I only get the item where the cursor is placed. I did not find any method to get all selected items.

Thanks for answers.


Solution

  • For some reason the functionality you need is not documented (at least in the only really usable wxPython/Phoenix docs). It is indeed present in the current wxWidgets documentation. But you can find it in the wxPython package:

    wxPython classic, in wx.dataview:

    def GetSelections(*args, **kwargs):
        """GetSelections(self) -> DataViewItemArray"""
        return _dataview.DataViewCtrl_GetSelections(*args, **kwargs)
    

    wxPython Phoenix, in .../site-packages/wx/dataview.pi

    def GetSelections(self):
        """
        GetSelections() -> DataViewItemArray
    
        Returns a list of the currently selected items.
        """
    

    It works at least in classic 2.9/3.0 (not tested by me for Phoenix).