FAQ
I am new to python and to wxWindows. I have tried searching google,
reading the documentation and trying to figure out some of the examples,
but I am stumped as to how to get information out of a listctrl at a
certain row and column. I tried to write a simple example to learn to
work with the listctrl as follows:
--------------------------------------
#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
# generated by wxGlade 0.4 on Wed Nov 16 10:23:06 2005

import wx

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel_1 = wx.Panel(self, -1)
self.list_ctrl_1 = wx.ListCtrl(self.panel_1, -1,
style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.label_1 = wx.StaticText(self.panel_1, -1, "label_1")

self.__set_properties()
self.__do_layout()

self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelected,
self.list_ctrl_1)
# end wxGlade


self.list_ctrl_1.InsertColumn(0,"Name")
self.list_ctrl_1.InsertColumn(1,"Address")
self.list_ctrl_1.SetColumnWidth(0, 215)
self.list_ctrl_1.SetColumnWidth(1, 55)
self.list_ctrl_1.InsertStringItem(0,"John Smith")
self.list_ctrl_1.SetStringItem(0,1, "123 Elm")
self.list_ctrl_1.InsertStringItem(1,"Tom Clark")
self.list_ctrl_1.SetStringItem(1,1, "415 W. 1st")

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2.Add(self.list_ctrl_1, 1, wx.EXPAND, 0)
sizer_2.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0)
self.panel_1.SetAutoLayout(True)
self.panel_1.SetSizer(sizer_2)
sizer_2.Fit(self.panel_1)
sizer_2.SetSizeHints(self.panel_1)
sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
# end wxGlade

def OnSelected(self, event): # wxGlade: MyFrame.<event_handler>
self.currentItem = event.m_itemIndex
#What do I put here to get the contents of the Address column?
#I want to do something like self.label_1.SetLabel(?)
#where the ? is the contents of the address column of the
selected row
event.Skip()

# end of class MyFrame


class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
self.SetTopWindow(frame_1)
frame_1.Show()
return 1

# end of class MyApp

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

But I can't figure out how to get the contents of the second column on
the selected row. Any help is appreciated.

Search Discussions

  • Limodou at Nov 17, 2005 at 1:06 am

    2005/11/17, Todd7 <nospam at please.net>:
    I am new to python and to wxWindows. I have tried searching google,
    reading the documentation and trying to figure out some of the examples,
    but I am stumped as to how to get information out of a listctrl at a
    certain row and column. I tried to write a simple example to learn to
    work with the listctrl as follows:
    I'v made some helper function as that:

    def getRowText(self, index, col):
    if index >= 0:
    return self.list_ctrl_1.GetItem(index, col).GetText()
    else:
    return ''

    def getSelRowText(self, col):
    return self.getRowText(self.getSelection(), col)

    def getSelection(self):
    return self.list_ctrl_1.GetNextItem(-1, wx.LIST_NEXT_ALL,
    wx.LIST_STATE_SELECTED)

    You can just use self.getSelRowText(1) to gain the second column text
    of selection row.
  • Todd7 at Nov 17, 2005 at 1:19 am
    Thank you very much. That is exactly what I needed.

    limodou <limodou at gmail.com> wrote in
    news:mailman.773.1132189602.18701.python-list at python.org:
    2005/11/17, Todd7 <nospam at please.net>:
    I am new to python and to wxWindows. I have tried searching google,
    reading the documentation and trying to figure out some of the
    examples, but I am stumped as to how to get information out of a
    listctrl at a certain row and column. I tried to write a simple
    example to learn to work with the listctrl as follows:
    I'v made some helper function as that:

    def getRowText(self, index, col):
    if index >= 0:
    return self.list_ctrl_1.GetItem(index, col).GetText()
    else:
    return ''

    def getSelRowText(self, col):
    return self.getRowText(self.getSelection(), col)

    def getSelection(self):
    return self.list_ctrl_1.GetNextItem(-1, wx.LIST_NEXT_ALL,
    wx.LIST_STATE_SELECTED)

    You can just use self.getSelRowText(1) to gain the second column text
    of selection row.
    --
    I like python!
    My Blog: http://www.donews.net/limodou
    NewEdit Maillist: http://groups.google.com/group/NewEdit

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 16, '05 at 5:09p
activeNov 17, '05 at 1:19a
posts3
users2
websitepython.org

2 users in discussion

Todd7: 2 posts Limodou: 1 post

People

Translate

site design / logo © 2022 Grokbase