【问题标题】:WxPython, ListCtrl add rows to the topWxPython,ListCtrl 将行添加到顶部
【发布时间】:2013-06-06 10:43:29
【问题描述】:

我有一个 ListCtrl 并且我希望将新行添加到列表的顶部(要向下推的先前行) 你能帮我吗?

谢谢!

【问题讨论】:

    标签: wxpython listctrl


    【解决方案1】:

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

    【讨论】:

    • 我认为你可能是正确的。但是我仍然只是设置index = 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 2013-05-16
      • 2011-10-13
      相关资源
      最近更新 更多