WxPython,ListCtrl将行添加到顶部

时间:2013-06-10 17:31:06

标签: wxpython listctrl

我有一个ListCtrl,我希望将新行添加到列表顶部(之前要下行的行) 你可以帮我吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

关于解决方案的有趣事实是,错误地我放了index = 0并且刚刚观察到它通过将行放在顶部来更新我的列表。即使使用OnUpdatePList函数追加新行,它也会附加在顶部。适用于我的应用程序。

def OnUpdatePList(self, pobj):
    sr = self.index + 1,
    index = 0
    self.list_ctrl.InsertStringItem(index, str(sr[0]))
    self.list_ctrl.SetStringItem(index, 1, unicode(pobj["title"]))
    self.list_ctrl.SetStringItem(index, 2, unicode(pobj["name"]))
    self.list_ctrl.SetStringItem(index, 3, unicode(pobj["date"]))
    self.list_ctrl.SetStringItem(index, 4, unicode(pobj["rdby"]))
    self.list_ctrl.SetStringItem(index, 5, unicode(pobj["dues"]))
    self.index += 1

答案 1 :(得分:1)

我不相信有一种内置方法可以实现这一目标。您必须保存数据,清除控件,然后插入新的行或后面的行。就个人而言,我会切换到使用ObjectListView小部件,您可以在其中使用对象列表。然后你可以将一个对象插入列表并重置控件。