Re: Sorting and listviews
- Posted by euman at bellsouth.net Jul 13, 2001
- 405 views
-- tagNMHDR NMHDR_hwndFrom = 0, NMHDR_idFrom = 4, NMHDR_code = 8, SIZEOF_NMHDR = 12 elsif iMsg = WM_NOTIFY then -- call_back iMsg = peek4s(lParam + NMHDR_code) if iMsg = LVN_COLUMNCLICK then -- could run a sort routine here elsif iMsg = NM_CLICK then end if return 0 Look into the Microsoft Platform SDK for listview LVN_COLUMNCLICK is the iMsg returned by the listview control when a header button is clicked. NM_CLICK is in the data area of the listview. I looked at Matts code in Win32lib and it isnt set up like this but this should give you an idea as where to start looking. I just finished writting my wrapper to the listview in streamlined API and it was really fun because the SDK is kindof confuseing. set your trace at WM_NOTIFY under LVN_COLUMNCLICK also, there is a flag that tells Windows to autosort the LV but am not sure where that is in win32lib but you'll need to remove this. look below for a very simple listview wrapper thats incomplete compared to win32lib but does the job I modified it some to show you how it might work. constant LVS_REPORT = 1, LVS_SHOWSELALWAYS = 8, LVIF_TEXT = 1, LVCF_FMT = 1, LVCF_WIDTH = 2, LVCF_TEXT = 4, LVCF_SUBITEM = 8, LVCF_ORDER = 20, LVCFMT_LEFT = 0, LVM_INSERTCOLUMN = 4123, LVS_SHAREIMAGELISTS = 40, LVM_SETITEM = 4102, LVM_INSERTITEM = 4103, LVM_SETBKCOLOR = 4097, LVM_SETTEXTBKCOLOR = 4134, LVM_SETTEXTCOLOR = 4132, LVM_SETEXTENDEDLISTVIEWSTYLE = 4150, LVS_EX_GRIDLINES = 1, LVS_EX_TRACKSELECT = 8, LVS_EX_HEADERDRAGDROP = 10, LVS_EX_FULLROWSELECT = 20, LVS_EX_ONECLICKACTIVATE = 40 constant lvcol_mask = 0, lvcol_fmt = 4, lvcol_cx = 8, lvcol_pszText = 12, lvcol_cchTextMax = 16, lvcol_iSubItem = 20, lvcol_iOrder = 24, sizeof_lvcol = 28 constant lvitem_mask = 0, lvitem_iItem = 4, lvitem_iSubItem = 8, lvitem_state = 12, lvitem_stateMask = 16, lvitem_pszText = 20, lvitem_cchTextMax = 24, lvitem_iImage = 28, lvitem_lParam = 32, lvitem_iIdent = 36, sizeof_lvitem = 40 global constant LVN_COLUMNCLICK = -108, NM_CLICK = -2 sequence data data = {{"Ringo","Starr"}, {"George","Harrison"}, {"Paul","McCartney"}, {"John","Lennon"} } procedure ListView_Column(atom id, atom lvcol, sequence text, integer item, integer width ) atom itxt, junk itxt = allocate_string(text) poke4( lvcol + lvcol_cx, width) poke4( lvcol + lvcol_pszText, itxt ) poke4( lvcol + lvcol_iSubItem, item ) junk = c_func(SendMessage,{id, LVM_INSERTCOLUMN, 0, lvcol}) end procedure global atom ListView1, lvcol global procedure MakeListView(atom hwnd, atom hInst, integer x1, integer y1, integer x2, integer y2) atom szName, szName2, item, seq, lvMask object junk lvMask = or_all({LVS_EX_FULLROWSELECT,LVS_EX_HEADERDRAGDROP,LVS_EX_GRIDLINES,LVS_EX_ONECL ICKACTIVATE, LVS_EX_TRACKSELECT }) szName = allocate_string("SysListView32") szName2 = allocate_string("ListView1") ListView1 = c_func(CreateWindow,{WS_EX_CLIENTEDGE, szName, szName2, or_all({WS_CHILD, WS_TABSTOP, WS_VISIBLE, #241, WS_BORDER, LVS_REPORT --LVS_SHOWSELALWAYS }), x1, y1, x2, y2, hwnd, 0, hInst, NULL}) free(szName) free(szName) junk = c_func(SendMessage,{ListView1, LVM_SETEXTENDEDLISTVIEWSTYLE, lvMask, lvMask}) junk = c_func(SendMessage,{ListView1,LVM_SETBKCOLOR, 0, 16744576}) junk = c_func(SendMessage,{ListView1,LVM_SETTEXTBKCOLOR, 0, 16744576}) junk = c_func(SendMessage,{ListView1,LVM_SETTEXTCOLOR, 0, 16777088}) junk = c_func(SendMessage,{ListView1,WM_SETREDRAW,0,0}) lvcol = allocate_struct(sizeof_lvcol) poke4( lvcol + lvcol_mask, or_all({LVCF_FMT, LVCF_SUBITEM, LVCF_TEXT, LVCF_WIDTH})) poke4( lvcol + lvcol_fmt, LVCFMT_LEFT) ListView_Column(ListView1, lvcol, "7", 7, 33 ) ListView_Column(ListView1, lvcol, "6", 6, 33 ) ListView_Column(ListView1, lvcol, "5", 5, 33 ) ListView_Column(ListView1, lvcol, "4", 4, 33 ) ListView_Column(ListView1, lvcol, "3", 3, 33 ) ListView_Column(ListView1, lvcol, "2", 2, 33 ) ListView_Column(ListView1, lvcol, "1", 1, 98 ) ListView_Column(ListView1, lvcol, "Date", 0, 100 ) item = allocate_struct(sizeof_lvitem) poke4( item + lvitem_mask, LVIF_TEXT ) for i = 1 to length(data) do seq = allocate_string(data[i][1]) poke4( item + lvitem_pszText, seq) poke4( item + lvitem_iItem,0) poke4( item + lvitem_iSubItem, 0) junk = c_func(SendMessage,{ListView1, LVM_INSERTITEM, 0, item }) seq = allocate_string(data[i][2]) poke4( item + lvitem_pszText, seq) poke4( item + lvitem_iItem,0) poke4( item + lvitem_iSubItem, 1) junk = c_func(SendMessage,{ListView1, LVM_SETITEM, 0, item }) -- etc....etc end for free(seq) junk = c_func(SendMessage,{ListView1,WM_SETFONT,c_func(GetStockObject,{DEFAULT_GUI_FONT }),0}) junk = c_func(SendMessage,{ListView1,WM_SETREDRAW,1,0}) end procedure Hope this helps some! Euman euman at bellsouth.net > > Hi All, > Two things. > Firstly is it possible to use your own sort routine when you click a column > header in a listview. > > Secondly has anyone written a sort routine they would like to share. My > problem is as follows: > N1-1-1 > N1-1-10 > N1-1-2 > N1-1-3 > > This is a typical numbering system used in master key systems and I would > rather have them display in a listview as follows: > N1-1-1 > N1-1-2 > N1-1-3 > N1-1-10 > > The default sort routine looks very unprofessional, and as I use the lists > to set the order of reports it is even more un professional. > > Thanks > Tony Steward > > Come Visit Me At www.locksdownunder.com