Info Posted July 11, 2011 Share Posted July 11, 2011 Is there any Listview style that can make the headers sort their subitems when clicked? I've been looking and didn't find any. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 11, 2011 Moderators Share Posted July 11, 2011 (edited) Info,You need to use either the simple _GUICtrlListView_SimpleSort function or rather more complicated _GUICtrlListView_SortItems/_GUICtrlListView_RegisterSortCallBack combination from the GuiListView UDF. The examples in the Help file are pretty easy to follow. M23Edit: Typnig! Edited July 11, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Info Posted July 11, 2011 Author Share Posted July 11, 2011 Ah, I was hoping there was some kind of listview style for doing this. Thanks Melba! Link to comment Share on other sites More sharing options...
Yashied Posted July 11, 2011 Share Posted July 11, 2011 A more complex but faster way: expandcollapse popup#Include <Date.au3> #Include <GUIConstantsEx.au3> #Include <GUIListView.au3> #Include <GUIHeader.au3> #Include <StructureConstants.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> $hProc = DllCallbackRegister('_SortProc', 'int', 'lparam;lparam;lparam') $pProc = DllCallbackGetPtr($hProc) $hForm = GUICreate('MyGUI', 400, 400) $LV = GUICtrlCreateListView('Number|Date', 10, 10, 380, 380) $hHdr = _GUICtrlListView_GetHeader(-1) Dim $FT[100][3] $tFT = DllStructCreate('dword;dword') $tDT = DllStructCreate('uint64', DllStructGetPtr($tFT)) For $i = 0 To UBound($FT) - 1 DllStructSetData($tFT, 2, Random(29400000, 30150000, 1)) $FT[$i][0] = StringFormat('%.2f', Random(0, 9)) $FT[$i][1] = DllStructGetData($tDT, 1) $FT[$i][2] = GUICtrlCreateListViewItem($FT[$i][0] & '|' & StringRegExpReplace(_Date_Time_FileTimeToStr($tFT), '\s.[^\s]*\z', ''), $LV) Next _GUICtrlHeader_SetItemFormat($hHdr, 0, BitOR(_GUICtrlHeader_GetItemFormat($hHdr, 0), $HDF_SORTUP)) _GUICtrlListView_SetSelectedColumn($LV, 0) _Sort($LV, 0) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() While 1 Switch GUIGetMsg() Case -3 ExitLoop EndSwitch WEnd DllCallbackFree($hProc) Func _Sort($CtrlID, $iSubItem) Return GUICtrlSendMsg($CtrlID, $LVM_SORTITEMS, $iSubItem, $pProc) EndFunc ;==>_Sort Func _SortProc($iItem1, $iItem2, $iSubItem) Local $Format = _GUICtrlHeader_GetItemFormat($hHdr, $iSubItem) Local $Order Select Case BitAND($Format, $HDF_SORTDOWN) $Order =-1 Case BitAND($Format, $HDF_SORTUP) $Order = 1 Case Else Return 0 EndSelect Select Case $FT[$iItem1 - $FT[0][2]][$iSubItem] > $FT[$iItem2 - $FT[0][2]][$iSubItem] Return $Order Case $FT[$iItem1 - $FT[0][2]][$iSubItem] < $FT[$iItem2 - $FT[0][2]][$iSubItem] Return -$Order Case Else Return 0 EndSelect EndFunc ;==>_SortProc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $hForm Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $CtrlID = DllStructGetData($tNMHDR, 'IDFrom') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $CtrlID Case $LV Switch $Code Case $LVN_COLUMNCLICK Local $tNMLISTVIEW = DllStructCreate('hwnd hWndFrom;uint_ptr IDFrom;uint_ptr Code;int Item;int SubItem;uint NewState;uint OldState;uint Changed;int X;int Y;lparam Param', $lParam) Local $SubItem = DllStructGetData($tNMLISTVIEW, 'SubItem') Local $Format = _GUICtrlHeader_GetItemFormat($hHdr, $SubItem) If Not BitAND($Format, BitOR($HDF_SORTDOWN, $HDF_SORTUP)) Then For $i = 0 To 1 _GUICtrlHeader_SetItemFormat($hHdr, $i, BitAND(_GUICtrlHeader_GetItemFormat($hHdr, $i), BitNOT(BitOR($HDF_SORTDOWN, $HDF_SORTUP)))) Next Switch $SubItem Case 0 ; Number _GUICtrlHeader_SetItemFormat($hHdr, $SubItem, BitOR(BitAND($Format, BitNOT(BitOR($HDF_SORTDOWN, $HDF_SORTUP))), $HDF_SORTUP)) Case 1 ; Date _GUICtrlHeader_SetItemFormat($hHdr, $SubItem, BitOR(BitAND($Format, BitNOT(BitOR($HDF_SORTDOWN, $HDF_SORTUP))), $HDF_SORTDOWN)) EndSwitch Else Select Case BitAND($Format, $HDF_SORTDOWN) _GUICtrlHeader_SetItemFormat($hHdr, $SubItem, BitOR(BitAND($Format, BitNOT($HDF_SORTDOWN)), $HDF_SORTUP)) Case BitAND($Format, $HDF_SORTUP) _GUICtrlHeader_SetItemFormat($hHdr, $SubItem, BitOR(BitAND($Format, BitNOT($HDF_SORTUP)), $HDF_SORTDOWN)) EndSelect EndIf _GUICtrlListView_SetSelectedColumn($LV, $SubItem) _Sort($LV, $SubItem) EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now