rasim Posted January 20, 2008 Posted January 20, 2008 Hi! How can sort items withs images in ListView? I tryed, but sorted only items, images stay on old place. expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> #include <GuiImageList.au3> $Gui = GUICreate("Test", 300, 200) $hListView = _GUICtrlListView_Create($GUI, "Items|SubItems", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon ($hImage, "shell32.dll", 3) _GUIImageList_AddIcon ($hImage, "shell32.dll", 1) _GUICtrlListView_SetImageList ($hListView, $hImage, 1) $ListItem1 = _GUICtrlListView_AddItem($hListView, "Item1",0) $ListItem2 = _GUICtrlListView_AddItem($hListView, "Item2",1) $ListSubItem1 = _GUICtrlListView_AddSubItem($hListView, 0, '1', 1) $ListSubItem1 = _GUICtrlListView_AddSubItem($hListView, 1, '2', 1) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $LVN_BEGINLABELEDIT Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam) Return False Case $LVN_ENDLABELEDIT Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam) Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text")) If StringLen(DllStructGetData($tBuffer, "Text")) Then Return True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc
Siao Posted January 20, 2008 Posted January 20, 2008 Use GUICtrlRegisterListViewSort(). "be smart, drink your wine"
GaryFrost Posted January 20, 2008 Posted January 20, 2008 expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Dim $nCurCol = -1 Dim $nSortDir = 1 Dim $bSet = 0 Dim $nCol = -1 $Gui = GUICreate("Test", 300, 200) $hListView = GUICtrlCreateListView("Items|SubItems", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, "shell32.dll", 3) _GUIImageList_AddIcon($hImage, "shell32.dll", 1) _GUICtrlListView_SetImageList($hListView, $hImage, 1) $ListItem1 = _GUICtrlListView_AddItem($hListView, "Item1", 0) _GUICtrlListView_SetItemParam($hListView, $ListItem1, _GUICtrlListView_GetItemCount($hListView) + 9999) $ListItem2 = _GUICtrlListView_AddItem($hListView, "Item2", 1) _GUICtrlListView_SetItemParam($hListView, $ListItem2, _GUICtrlListView_GetItemCount($hListView) + 9999) $ListSubItem1 = _GUICtrlListView_AddSubItem($hListView, 0, '1', 1) $ListSubItem1 = _GUICtrlListView_AddSubItem($hListView, 1, '2', 1) GUICtrlRegisterListViewSort($hListView, "LVSort") ; Register the function "LVSort" for the sorting callback GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hListView $bSet = 0 $nCurCol = $nCol GUICtrlSendMsg($hListView, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($hListView), 0) DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($hListView), "int", 0, "int", 1) EndSwitch WEnd ; Our sorting callback funtion Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort Local $tInfo = DllStructCreate($tagLVFINDINFO) DllStructSetData($tInfo, "Flags", $LVFI_PARAM) ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn DllStructSetData($tInfo, "Param", $nItem1) $val1 = _GUICtrlListView_FindItem($hWnd, -1, $tInfo) ConsoleWrite("$val1: " & $val1 & @LF) DllStructSetData($tInfo, "Param", $nItem2) $val2 = _GUICtrlListView_FindItem($hWnd, -1, $tInfo) $val1 = _GUICtrlListView_GetItemText($hWnd, $val1, $nColumn) $val2 = _GUICtrlListView_GetItemText($hWnd, $val2, $nColumn) $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ;==>LVSort SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
GaryFrost Posted January 20, 2008 Posted January 20, 2008 Thanks guys! NPIn the next Release and/or Beta look for _GUICtrlListView_RegisterSortCallBack, should be much easier to use then the GUICtrlRegisterListViewSort SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
rasim Posted January 20, 2008 Author Posted January 20, 2008 NPIn the next Release and/or Beta look for _GUICtrlListView_RegisterSortCallBack, should be much easier to use then the GUICtrlRegisterListViewSortGlad for this news! Wait...
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