Sign in to follow this  
Followers 0
goldenix

[SOLVED]_Sorting listview Column.

7 posts in this topic

#1 ·  Posted (edited)

EDIT: Original Q Was How to sort a Listview Column by Calling a function like:

_ListView_Sort(2) ; Sort Column 2

if you are facing the same Problem dont bother to look into the help file(its a waist of time!), the solution is hire:

http://www.autoitscript.com/forum/index.ph...63709&st=12

Full topic:

http://www.autoitscript.com/forum/index.php?showtopic=63709

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites



Bump*

I stripped the code to: But its not sorting properly now..Any Ideas Why?

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

Func _a()
    $tInfo = DllStructCreate($tagNMLISTVIEW)
     _GUICtrlListView_SimpleSort(GUICtrlGetHandle($hListView), $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
EndFunc
 
_a()

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

In my Email_zak & Log_View projects (see my signature) I use:

GUICtrlRegisterListViewSort($ListView1, "LVSort")

Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    If $nColumn = 0 Then ; Zakaznik
        $val1 = GetSubItemText($ListView1, $nItem1, $nColumn)
        $val2 = GetSubItemText($ListView1, $nItem2, $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
                Return $nResult
    Else ; do nothing when clicked on header at other columns
        Return 0 ; No change of item1 and item2 positions
    EndIf
EndFunc

Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
    Local $stLvfi       = DllStructCreate("uint;ptr;int;int[2];int")
    DllStructSetData($stLvfi, 1, $LVFI_PARAM)
    DllStructSetData($stLvfi, 3, $nItemID)

    Local $stBuffer     = DllStructCreate("char[260]")
    $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi))

    Local $stLvi        = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
    DllStructSetData($stLvi, 1, $LVIF_TEXT)
    DllStructSetData($stLvi, 2, $nIndex)
    DllStructSetData($stLvi, 3, $nColumn)
    DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
    DllStructSetData($stLvi, 7, 260)

    GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi));

    $sItemText  = DllStructGetData($stBuffer, 1)
    $stLvi = 0
    $stLvfi = 0
    $stBuffer = 0

    Return $sItemText
EndFunc

Func DoSort()
    ; sort by first column
    $struct_NMLISTVIEW = DllStructCreate("hwnd;uint;uint;int;int;uint;uint;uint;int;int;int")
    DllStructSetData($struct_NMLISTVIEW,1,GUICtrlGetHandle($ListView1))
    DllStructSetData($struct_NMLISTVIEW,2,$ListView1)
    DllStructSetData($struct_NMLISTVIEW,3,$LVN_COLUMNCLICK)
    DllStructSetData($struct_NMLISTVIEW,4,-1) ; item = -1
    DllStructSetData($struct_NMLISTVIEW,5,0) ; subitem=0

    _SendMessage($Form1, $WM_NOTIFY, $ListView1, DllStructGetPtr($struct_NMLISTVIEW))
    $struct_NMLISTVIEW = 0
EndFunc

Just call DoSort() after you fill up your Listview by data - it simulates click on header of first column.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

In my Email_zak & Log_View projects (see my signature) I use: Just call DoSort() after you fill up your Listview by data - it simulates click on header of first column.

Edit, Cant do nothing with ur project files, Getting loads & loads of errors with this latest autoit version. If I find some old versions, ill try looking into ur projects again.

Try Running this: see if you also Get these errors?

WARNING: $LVM_GETITEM: possibly used before declaration.

ERROR: $LVM_GETITEM: undeclared global variable.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 193, 115)
;~ Create listview
    $hListView = _GUICtrlListView_Create ($Form1, "", 2, 2, 595, 400)
     _GUICtrlListView_SetExtendedListViewStyle ($hListView, BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER))
;~  ; Add columns
    _GUICtrlListView_AddColumn ($hListView, "Handle", 93)
    _GUICtrlListView_AddColumn ($hListView, "Title", 449)
    
    GUICtrlRegisterListViewSort($hListView, "LVSort") ; <<<<<<<<<<<<==========
    
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_Fill_List()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


func _Fill_List()
$row = 0
$var = WinList()
    For $i = 1 to $var[0][0]
;~      Add winnames into list
        if $var[$i][0] <> '' Then                     
            _GUICtrlListView_AddItem ($hListView, $var[$i][1], $row)           ;$var[$i][1] = [Rownr][Column2]
            _GUICtrlListView_AddSubItem ($hListView, $row, $var[$i][0] , 1)    ;Col 3 text
            $row = $row + 1
        EndIf
    Next
    DoSort() ; <<<<<<<<<<<<==========
EndFunc


; <<<<<<<<<<<<==========
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    If $nColumn = 0 Then ; Zakaznik
        $val1 = GetSubItemText($hListView, $nItem1, $nColumn)
        $val2 = GetSubItemText($hListView, $nItem2, $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
                Return $nResult
    Else ; do nothing when clicked on header at other columns
        Return 0 ; No change of item1 and item2 positions
    EndIf
EndFunc
; <<<<<<<<<<<<==========
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
    Local $stLvfi       = DllStructCreate("uint;ptr;int;int[2];int")
    DllStructSetData($stLvfi, 1, $LVFI_PARAM)
    DllStructSetData($stLvfi, 3, $nItemID)

    Local $stBuffer     = DllStructCreate("char[260]")
    $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi))

    Local $stLvi        = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
    DllStructSetData($stLvi, 1, $LVIF_TEXT)
    DllStructSetData($stLvi, 2, $nIndex)
    DllStructSetData($stLvi, 3, $nColumn)
    DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
    DllStructSetData($stLvi, 7, 260)

    GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi));

    $sItemText  = DllStructGetData($stBuffer, 1)
    $stLvi = 0
    $stLvfi = 0
    $stBuffer = 0

    Return $sItemText
EndFunc
; <<<<<<<<<<<<==========
Func DoSort()
    ; sort by first column
    $struct_NMLISTVIEW = DllStructCreate("hwnd;uint;uint;int;int;uint;uint;uint;int;int;int")
    DllStructSetData($struct_NMLISTVIEW,1,GUICtrlGetHandle($hListView))
    DllStructSetData($struct_NMLISTVIEW,2,$hListView)
    DllStructSetData($struct_NMLISTVIEW,3,$LVN_COLUMNCLICK)
    DllStructSetData($struct_NMLISTVIEW,4,-1) ; item = -1
    DllStructSetData($struct_NMLISTVIEW,5,0) ; subitem=0

    _SendMessage($Form1, $WM_NOTIFY, $hListView, DllStructGetPtr($struct_NMLISTVIEW))
    $struct_NMLISTVIEW = 0
EndFunc
; <<<<<<<<<<<<==========
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

About errors: Just accomodate list of your include files.

Projects in my signature are older so take it as concept ideas and not as "exact solution" for latest AutoIt.

But you can't use _GUICtrlListView_Create() if you wish to use GUICtrlRegisterListViewSort()

You must use GUICtrlCreateListView()

Edited by Zedna

Share this post


Link to post
Share on other sites

goldenix

See a _GUICtrlListView_SortItems() function in the help file.

Share this post


Link to post
Share on other sites

goldenix

See a _GUICtrlListView_SortItems() function in the help file.

If the help file Sorting example would be as simple as calling this to perform the sort:

_GUICtrlListView_SimpleSort($listview, 'Descending', $Column = 1)

Then I wouldnt be asking.

Im back to autoit ver 3.2.10 & still No nothing works. Can explain how can I write this:

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)oÝ÷ ظ¤zØb±«­¢+Ù]5}9=Q%d ¤oÝ÷ Ø  Ý­va¢Ç¯j¸nW¬­êkzǧµÊ{MúiÝÓ~¢2È4ߨ°=ªÚMúSÚ­©´ß¨VÒâ²Õb{
7êÖ 4ÁÃGMú´Ó
ܡ׺Y¡×¨~Øb±«­¢+ÙU%I¥ÍÑÉ5Í ÀÌØí]5}9=Q%d°ÅÕ½Ðí]5}9=Q%dÅÕ½Ðì¤)Õ¹]5}9=Q%d ÀÌØí¡]¹°ÀÌØí¥5Í°ÀÌØí¥ÝAÉ´°ÀÌØí¥±AÉ´¤($(1½°ÀÌØí¡]¹É½´°ÀÌØí¥%ɽ´°ÀÌØí¥
½°ÀÌØíÑ95!H°ÀÌØí¡]¹1¥ÍÑY¥Ü(ÀÌØí¡]¹1¥ÍÑY¥ÜôÀÌØí¡1¥ÍÑY¥Ü(%9½Ð%Í!]¹ ÀÌØí¡1¥ÍÑY¥Ü¤Q¡¸ÀÌØí¡]¹1¥ÍÑY¥ÜôU%
ÑɱÑ!¹± ÀÌØí¡1¥ÍÑY¥Ü¤((ÀÌØíÑ95!Hô±±MÑÉÕÑ
ÉÑ ÀÌØíÑ95!H°ÀÌØí¥±AÉ´¤(ÀÌØí¡]¹É½´ô!]¹¡±±MÑÉÕÑÑÑ ÀÌØíÑ95!H°ÅÕ½Ðí¡]¹É½´ÅÕ½Ð줤(ÀÌØí¥%ɽ´ô±±MÑÉÕÑÑÑ ÀÌØíÑ95!H°ÅÕ½Ðí%ɽ´ÅÕ½Ðì¤(ÀÌØí¥
½ô±±MÑÉÕÑÑÑ ÀÌØíÑ95!H°ÅÕ½Ðí
½ÅÕ½Ðì¤(MÝ¥Ñ ÀÌØí¡]¹É½´(
ÍÀÌØí¡]¹1¥ÍÑY¥Ü(MÝ¥Ñ ÀÌØí¥
½(
ÍÀÌØí1Y9}
=1U59
1%
,ì½±Õµ¸Ý̱¥­(1½°ÀÌØíÑ%¹¼ô±±MÑÉÕÑ
ÉÑ ÀÌØíÑ951%MQY%°ÀÌØí¥±AÉ´¤(}U%
Ñɱ1¥ÍÑY¥Ý}M¥µÁ±M½ÉÐ ÀÌØí¡]¹1¥ÍÑY¥Ü°ÀÌØí }M
9%9°±±MÑÉÕÑÑÑ ÀÌØíÑ%¹¼°ÅÕ½ÐíMÕ%Ñ´ÅÕ½Ð줤((¹MÝ¥Ñ (¹MÝ¥Ñ (IÑÕɸÀÌØíU%}IU95M)¹Õ¹ìôôÐí]5}9=Q%

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0