Making items visible in wxPython wxListCtrl

Discussion in 'Python' started by Piet, May 18, 2004.

  1. Piet

    Piet Guest

    Hi there.
    I am trying to display tabular data in a wxListCtrl. What I get from
    the script below are only the headers, not the items themselves. The
    documentation didn´t help me much; instead I was lost in ListItemId´s
    and different possibilities of inserting items and strings. I am sure
    the solution is only one step away, but I need somebody to point in
    the direction. Heres the script:

    from wxPython.wx import *
    class MainWindow(wxFrame):
    def __init__(self,parent,id,title):
    wxFrame.__init__(self,parent,-1, title,
    style=wxDEFAULT_FRAME_STYLE)
    self.panel = wxPanel(self,-1)
    self.Lctrl = wxListCtrl(self.panel,-1,size=(200,200),style =
    wxLC_REPORT)
    for i in range(2):
    self.Lctrl.InsertColumn(i,"Column"+str(i),format=wxLIST_FORMAT_LEFT,width=100)
    self.Lctrl.SetStringItem(i,1,"Hi")
    self.Lctrl.SetStringItem(i,2,"there")
    self.Lctrl.SetItemData(i,1)


    app = wxPySimpleApp()
    frame = MainWindow(None, -1, "List Control Test")
    frame.Show(1)
    app.MainLoop()

    Best regards

    Peter
    Piet, May 18, 2004
    #1
    1. Advertising

  2. Piet

    Greg Krohn Guest

    Piet wrote:
    > Hi there.
    > I am trying to display tabular data in a wxListCtrl. What I get from
    > ...


    I hope this clears it up.


    from wxPython.wx import *
    class MainWindow(wxFrame):
    def __init__(self,parent,id,title):
    wxFrame.__init__(self,parent,-1, title,
    style=wxDEFAULT_FRAME_STYLE)
    self.panel = wxPanel(self,-1)
    self.Lctrl = wxListCtrl(self.panel,-1,
    size=(200,200),style =wxLC_REPORT)

    # for i in range(2):
    # self.Lctrl.InsertColumn(i, "Column"+str(i),
    # format=wxLIST_FORMAT_LEFT,width=100)
    # self.Lctrl.SetStringItem(i,1,"Hi")
    # self.Lctrl.SetStringItem(i,2,"there")
    # self.Lctrl.SetItemData(i,1)

    self.Lctrl.InsertColumn(0, "Name")
    self.Lctrl.InsertColumn(1, "ID")
    self.Lctrl.InsertColumn(2, "Spam Level")

    people = [["George", "3t4d3", "5"],
    ["Beth", "34g245", "3"],
    ["Zaphod", "424242", "42"]]

    # Notice you use InsertStringItem for the first item
    # in the row and then use SetStringItem for the rest
    for index, (name, id, spam) in enumerate(people):
    self.Lctrl.InsertStringItem(index, name)
    self.Lctrl.SetStringItem(index, 1, id)
    self.Lctrl.SetStringItem(index, 2, spam)


    app = wxPySimpleApp()
    frame = MainWindow(None, -1, "List Control Test")
    frame.Show(1)
    app.MainLoop()



    > Best regards
    >
    > Peter


    Ditto,
    greg
    Greg Krohn, May 18, 2004
    #2
    1. Advertising

  3. Piet

    moma Guest

    Piet wrote:
    > Hi there.
    > I am trying to display tabular data in a wxListCtrl. What I get from
    > the script below are only the headers, not the items themselves. The
    > documentation didn´t help me much; instead I was lost in ListItemId´s
    > and different possibilities of inserting items and strings. I am sure
    > the solution is only one step away, but I need somebody to point in
    > the direction. Heres the script:
    >
    > from wxPython.wx import *
    > class MainWindow(wxFrame):
    > def __init__(self,parent,id,title):
    > wxFrame.__init__(self,parent,-1, title,
    > style=wxDEFAULT_FRAME_STYLE)
    > self.panel = wxPanel(self,-1)
    > self.Lctrl = wxListCtrl(self.panel,-1,size=(200,200),style =
    > wxLC_REPORT)
    > for i in range(2):
    > self.Lctrl.InsertColumn(i,"Column"+str(i),format=wxLIST_FORMAT_LEFT,width=100)
    > self.Lctrl.SetStringItem(i,1,"Hi")
    > self.Lctrl.SetStringItem(i,2,"there")
    > self.Lctrl.SetItemData(i,1)
    >
    >
    > app = wxPySimpleApp()
    > frame = MainWindow(None, -1, "List Control Test")
    > frame.Show(1)
    > app.MainLoop()
    >
    > Best regards
    >
    > Peter



    Mixing rows and columns ?


    > for i in range(2):
    >> self.Lctrl.InsertColumn(i,"Column"+str(i),format=wxLIST_FORMAT_LEFT,width=100)
    >> self.Lctrl.SetStringItem(i,1,"Hi")
    >> self.Lctrl.SetStringItem(i,2,"there")
    >> self.Lctrl.SetItemData(i,1)
    >>


    # Create 2 columns
    for i in range(2):
    self.Lctrl.InsertColumn(i,"Column"+str(i),
    format=wxLIST_FORMAT_LEFT,width=100)


    # Add 6 rows of data
    for i in range(6):
    self.Lctrl.InsertStringItem(i,"Hi") # Col 0
    self.Lctrl.SetStringItem(i,1,"there") # Col 1
    self.Lctrl.SetItemData(i,1)



    http://wiki.wxpython.org/index.cgi/ListControls


    Cheers,
    // moma
    http://www.futuredesktop.org
    moma, May 18, 2004
    #3
  4. Piet

    Piet Guest

    Shame on me....
    Looks like as if wanted to populate a non-existing column with data.
    Anyway, now evrything is working properly. Many, many thanks! That helped me a lot.

    Piet
    Piet, May 19, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Carter
    Replies:
    1
    Views:
    522
    Steve Zatz
    Dec 1, 2003
  2. Piet
    Replies:
    4
    Views:
    1,444
    RichH
    Jul 5, 2004
  3. Fabio Pliger

    wxpython wxlistctrl with combo

    Fabio Pliger, Jun 13, 2005, in forum: Python
    Replies:
    1
    Views:
    387
    Franz Steinhaeusler
    Jun 14, 2005
  4. imperialguy
    Replies:
    0
    Views:
    168
    imperialguy
    Apr 13, 2011
  5. Miki Tebeka

    Re: Sort items in wxListCtrl

    Miki Tebeka, Nov 1, 2011, in forum: Python
    Replies:
    2
    Views:
    417
    Miki Tebeka
    Nov 3, 2011
Loading...

Share This Page