[wxPython] Unable to get cell text from ListCtrl

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Unable to get cell text from ListCtrl

Miles Clark

Hi -

I'm unable to retrieve the text contained in columns within a wxListCtrl
in report mode.  When using GetItem(row, col), the m_text field of the
resulting item is always an empty string, even though the other fields
look correct.  I can't see another way to retrieve this info.  Any ideas?

I've included a sample program as an example. The output of Type and Desc
in OnListSelect are always ''....


thanks in advance!

miles


-------------------

from wxPython.wx import *

LIST_ID = 101

class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title,
                         wxDefaultPosition, wxSize(400, 400))
        self.panel = wxPanel(self, -1)
        self.list = wxListCtrl(self.panel, LIST_ID,
                               wxPoint(10, 10), wxSize(370, 330),
                               wxLC_REPORT|wxSUNKEN_BORDER)
        self.list.InsertColumn(0, "Id")
        self.list.InsertColumn(1, "Type")
        self.list.InsertColumn(2, "Description")

        self.insertRow(self.list, 0, 'CD', 'Dark Side of the Moon')
        self.insertRow(self.list, 1, 'DVD', 'The Matrix')
        self.insertRow(self.list, 2, 'Book', 'Crime and Punishment')
       
        self.list.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
        self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
        self.list.SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER)
       
        EVT_LIST_ITEM_SELECTED(self.panel, LIST_ID, self.OnListSelect)
       
        self.panel.Layout()
        return

    def OnListSelect(self, event):
        type = self.list.GetItem(event.m_itemIndex, col=1).m_text
        desc = self.list.GetItem(event.m_itemIndex, col=2).m_text
        print ('Row Selected: Id: %d, Type: %s, Desc: %s' %
               (event.m_itemIndex, `type`, `desc`))
        return

    def insertRow(self, list, row, type, desc):
        list.InsertStringItem(row, 'label' + `row`)
        list.SetStringItem(row, 0, `row`)
        list.SetStringItem(row, 1, type)
        list.SetStringItem(row, 2, desc)
        return
       
    def OnCloseWindow(self, event):
        self.Destroy()
        return



class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(None, -1, 'ListCtrl Test')
        frame.Show(1)
        self.SetTopWindow(frame)
        return 1


if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

   



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Unable to get cell text from ListCtrl

Robin Dunn
>
> Hi -
>
> I'm unable to retrieve the text contained in columns within a wxListCtrl
> in report mode.  When using GetItem(row, col), the m_text field of the
> resulting item is always an empty string, even though the other fields
> look correct.  I can't see another way to retrieve this info.  Any ideas?
>

This is a bug.  I forgot to set any values in the mask when fetching the
item, so it didn't fill in any of them.  The fix will be in CVS shortly and I
hope to have my semi-automatic-almost-daily <grin> build script done for the
MSW version today too.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users