473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sort items in UltimateListCtrl

15
I want to create an ultimate list ctrl based table where the user can sort the columns by clicking on the column header. Here's the code I attempted:

Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import wx.lib.mixins.listctrl as listmix
  3. from wx.lib.agw import ultimatelistctrl as ULC
  4.  
  5. APPNAME='Sortable Ultimate List Ctrl'
  6. APPVERSION='1.0'
  7. MAIN_WIDTH=300
  8. MAIN_HEIGHT=300
  9.  
  10. musicdata = {
  11. 0 : ("Bad English", "The Price Of Love"),
  12. 1 : ("DNA featuring Suzanne Vega", "Tom's Diner"),
  13. 2 : ("George Michael", "Praying For Time"),
  14. 3 : ("Gloria Estefan", "Here We Are"),
  15. 4 : ("Linda Ronstadt", "Don't Know Much"),
  16. 5 : ("Michael Bolton", "How Am I Supposed To Live Without You"),
  17. 6 : ("Paul Young", "Oh Girl"),
  18. }
  19.  
  20. ########################################################################
  21. class TestUltimateListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
  22.  
  23.     #----------------------------------------------------------------------
  24.     def __init__(self, parent):
  25.         wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(MAIN_WIDTH,MAIN_HEIGHT))
  26.  
  27.         self.index = 0
  28.  
  29.         self.list_ctrl = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
  30.         self.list_ctrl.InsertColumn(0, "Artist")
  31.         self.list_ctrl.InsertColumn(1, "Title", wx.LIST_FORMAT_RIGHT)
  32.         self.list_ctrl.InsertColumn(2, "Download")
  33.  
  34.         items = musicdata.items()
  35.         index = 0
  36.         for key, data in items:
  37.             pos=self.list_ctrl.InsertStringItem(index, data[0])
  38.             self.list_ctrl.SetStringItem(index, 1, data[1])
  39.             #self.list_ctrl.SetStringItem(index, 2, data[2])
  40.             button = wx.Button(self.list_ctrl, id=wx.ID_ANY, label="Download")
  41.         self.list_ctrl.SetItemWindow(pos, col=2, wnd=button, expand=True)
  42.             self.list_ctrl.SetItemData(index, key)
  43.             index += 1
  44.  
  45.         # Now that the list exists we can init the other base class,
  46.         # see wx/lib/mixins/listctrl.py
  47.         self.itemDataMap = musicdata
  48.         listmix.ColumnSorterMixin.__init__(self, 3)
  49.         self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list_ctrl)
  50.  
  51.         sizer = wx.BoxSizer(wx.VERTICAL)
  52.         sizer.Add(self.list_ctrl, 1, wx.ALL|wx.EXPAND, 5)
  53.         self.SetSizer(sizer)
  54.  
  55.  
  56.     def GetListCtrl(self):
  57.         return self.list_ctrl
  58.  
  59.     #----------------------------------------------------------------------
  60.     def OnColClick(self, event):
  61.         pass
  62.  
  63. ########################################################################
  64. class MyForm(wx.Frame):
  65.  
  66.     #----------------------------------------------------------------------
  67.     def __init__(self):
  68.         wx.Frame.__init__(self,None,wx.ID_ANY,'%s v%s' % (APPNAME,APPVERSION),size=(MAIN_WIDTH,MAIN_HEIGHT),style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
  69.  
  70.         # Add a panel so it looks the correct on all platforms
  71.         panel = TestUltimateListCtrlPanel(self)
  72.  
  73. #----------------------------------------------------------------------
  74. # Run the program
  75. if __name__ == "__main__":
  76.     app = wx.App(False)
  77.     frame = MyForm()
  78.     frame.Show()
  79.     app.MainLoop()
Clicking on the column does not sort the 'Artist' or 'Title' fields. I want to be able to sort them when the user clicks on the column headers. Please help.

This is how it looks like

Nov 5 '11 #1
0 1436

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Krick | last post by:
I was talking to a co-worker today. He used to work in computers way, way, back in the days when computers had little to no memory, operating systems hadn't been invented yet, and everything was...
7
by: juglesh | last post by:
Hello, I would like to be able to have the user sort a list of items similarly to the way you sort your queue on Netflix.com. (the numbers dont change dynamically on netflix, they must be doing...
4
by: Robin Tucker | last post by:
How do I sort the items in a list box? I am using a class derived from IComparer to sort items on columns in a ListView, but the ListBox doesn't support this kind of facility. The "items" in my...
11
by: Shi Mu | last post by:
I have a list like ,,,]. How can I sort the list based on the second value in the item? That is, I want the list to be: ,,,]
5
by: Jan Smith | last post by:
I've searched the overloads for the Array.Sort method, and I haven't found a clear answer to my question. Maybe it's not in Array.Sort. Here's the question: I initialize an array X with the...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
3
by: Stuart | last post by:
I am using Visual Basic 2005. I have created a two dimensional ArrayList named aSystem that is populated as follows:- aSystem.Add(New PickList(0, "Undefined")) aSystem.Add(New PickList(-1,...
0
by: Michael Hamm | last post by:
I'd like to sort items in an XML file using XSLT. Say I have <item><n>Jefferson</n><n>Hancock</n><foo>bar</foo></item> <item><n>Washington</n><foo>baz</foo></item>...
4
by: rn5a | last post by:
Can the items in a ListBox be sorted by the name of the items? The ListBox actually lists all directories & files existing in a directory on the server. Note that all the directories should be...
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.