problem with editing labels in wx list control
do you guys have any idea how to edit the the labels in the second column in a wx.ListCtrl here is the code that i used to create that list .. Note th开发者_Python百科at the first column is the only editable one . how can i make the other one editable too?
self.lCUsers=wx.ListCtrl(self,style=wx.LC_EDIT_LABELS | wx.LC_REPORT |wx.LC_VRULES | wx.LC_HRULES)
self.lCUsers.SetPosition((20,40))
self.lCUsers.SetSize((300,350))
self.lCUsers.InsertColumn(0,'Users',format=wx.LIST_FORMAT_LEFT ,width=220)
self.lCUsers.InsertColumn(1,'Value',format=wx.LIST_FORMAT_LEFT,width=80)thankx in advance
You can use the TextEditMixin
import wx
from wx.lib.mixins.listctrl import TextEditMixin
class EditableTextListCtrl(wx.ListCtrl, TextEditMixin):
def __init__(self, parent, ID, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
TextEditMixin.__init__(self)
class MyDialog(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id)
listCtrl = EditableTextListCtrl(self, -1, style=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES, size=(300, 200))
listCtrl.InsertColumn(0, 'State')
listCtrl.InsertColumn(1, 'Capital')
listCtrl.SetColumnWidth(0, 140)
listCtrl.SetColumnWidth(1, 153)
states = ['Slovakia', 'Poland', 'Hungary']
capitals = ['Brastislava', 'Warsaw', 'Budapest']
for i in range(3):
listCtrl.InsertStringItem(0, states[i])
listCtrl.SetStringItem(0, 1, capitals[i])
class MyApp(wx.App):
def OnInit(self):
dia = MyDialog(None, -1, 'capitals.py')
dia.ShowModal()
dia.Destroy()
return True
app = MyApp(0)
app.MainLoop()
精彩评论