Sign in to follow this  
Followers 0
rootx

_GUICtrlListView_SimpleSort help

3 posts in this topic

#1 ·  Posted

I would like to order the title column, but when I do the icon does not exactly match, do you have any ideas? THX

files ini and icon https://ufile.io/03x69

#include <StructureConstants.au3>
#include <ButtonConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiImageList.au3>
#include <StaticConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <WinAPI.au3>
#include <WinAPITheme.au3>
#include <Color.au3>
#include <ColorConstants.au3>
#include <WinAPIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

Global $IEControl,$tini = @ScriptDir&"\test.ini"
Global $ListView, $g_bSortSense = False ; Set initial ascending sort

$Form1 = GUICreate("Form1", 800, 600, 192, 124)
$ListView = GUICtrlCreateListView("",  10, 10, 780, 580);, -1, BitOR($LVS_EX_FULLROWSELECT, 0x00010000))
;_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetFont($ListView, 8, Default, Default, "Arial")
GUICtrlSetResizing($ListView,1); 102 + 2)
_GUICtrlListView_AddColumn($ListView, "Title", 400)
_GUICtrlListView_AddColumn($ListView, "Country", 50)
_GUICtrlListView_AddColumn($ListView, "Path", 320)

read()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        Case $ListView
    EndSwitch
WEnd

Func read()
    Local $tot = 0
    If FileExists($tini) Then
        $hImage2 = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()
        $aArrays = IniReadSectionNames($tini)

        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1
                $n = IniRead($tini, $aArrays[$i], "name", "")
                $z = IniRead($tini, $aArrays[$i], "ico", "")
                $r = IniRead($tini, $aArrays[$i], "region", "")
                ConsoleWrite($z&@CRLF)
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap2 = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled2 = _GDIPlus_ImageResize($hBitmap2, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled2)
                _GDIPlus_BitmapDispose($hBitmap_scaled2)
                _GDIPlus_BitmapDispose($hBitmap2)
                $ico = _GUIImageList_Add($hImage2, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($ListView, $hImage2, 1)
                _GUICtrlListView_AddItem($ListView, $n, $ico)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $r, 1)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $aArrays[$i], 2)
                $tot += 1
            Next
             _GUICtrlListView_SimpleSort($ListView, $g_bSortSense, 0, False)
            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

I can not understand why if I use icons, columns are not sorted correctly. Any suggestion.. THX

 

#include <StructureConstants.au3>
#include <ButtonConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiImageList.au3>
#include <StaticConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <WinAPI.au3>
#include <WinAPITheme.au3>
#include <Color.au3>
#include <ColorConstants.au3>
#include <WinAPIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

Global $IEControl,$tini = @ScriptDir&"\test.ini"
Global $ListView, $g_bSortSense = False

$Form1 = GUICreate("Form1", 800, 600, 192, 124)
$ListView = GUICtrlCreateListView("",  10, 10, 780, 580);, -1, BitOR($LVS_EX_FULLROWSELECT, 0x00010000))
;_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetFont($ListView, 8, Default, Default, "Arial")
GUICtrlSetResizing($ListView,1); 102 + 2)
_GUICtrlListView_AddColumn($ListView, "Icon", 70)
_GUICtrlListView_AddColumn($ListView, "Name", 330)
_GUICtrlListView_AddColumn($ListView, "Country", 50)
_GUICtrlListView_AddColumn($ListView, "Path", 320)

read()
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
#EndRegion ### END Koda GUI section ###

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

        Case $ListView
    EndSwitch
WEnd

Func read()
    Local $tot = 0
    If FileExists($tini) Then
        $hImage2 = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()
        $aArrays = IniReadSectionNames($tini)

        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1

                $n = IniRead($tini, $aArrays[$i], "name", "")
                $z = IniRead($tini, $aArrays[$i], "ico", "")
                $r = IniRead($tini, $aArrays[$i], "region", "")
                ConsoleWrite($z&@CRLF)
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap2 = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled2 = _GDIPlus_ImageResize($hBitmap2, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled2)
                _GDIPlus_BitmapDispose($hBitmap_scaled2)
                _GDIPlus_BitmapDispose($hBitmap2)
                $ico = _GUIImageList_Add($hImage2, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($ListView, $hImage2, 1)
                _GUICtrlListView_AddItem($ListView, "", $ico)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $n, 1)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $r, 2)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $aArrays[$i], 3)
                $tot += 1
            Next
            _GUICtrlListView_SimpleSort($ListView, $g_bSortSense, 1, False)
            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    Local $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Ok, I found I way to order the colums, But... How i can sort the listview before it is loaded??? Thx

#include <StructureConstants.au3>
#include <ButtonConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiImageList.au3>
#include <StaticConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <WinAPI.au3>
#include <WinAPITheme.au3>
#include <Color.au3>
#include <ColorConstants.au3>
#include <WinAPIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

Global $IEControl,$tini = @ScriptDir&"\test.ini"
Global $ListView

$Form1 = GUICreate("Form1", 800, 600, 192, 124)
$ListView = GUICtrlCreateListView("",  10, 10, 780, 580, -1, BitOR($LVS_EX_FULLROWSELECT, 0x00010000))
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetFont($ListView, 8, Default, Default, "Arial")
GUICtrlSetResizing($ListView,1); 102 + 2)
_GUICtrlListView_AddColumn($ListView, "Icon", 70)
_GUICtrlListView_AddColumn($ListView, "Name", 330)
_GUICtrlListView_AddColumn($ListView, "Country", 50)
_GUICtrlListView_AddColumn($ListView, "Path", 320)

read()
GUISetState(@SW_SHOW)
   _GUICtrlListView_RegisterSortCallBack($ListView)

#EndRegion ### END Koda GUI section ###

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

        Case $ListView
            _GUICtrlListView_SortItems($ListView, GUICtrlGetState($ListView))
    EndSwitch
WEnd
  _GUICtrlListView_RegisterSortCallBack($ListView)
   GUIDelete()
Func read()
    Local $tot = 0
    If FileExists($tini) Then
        $hImage2 = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()

        $aArrays = IniReadSectionNames($tini)



        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1

                $n = IniRead($tini, $aArrays[$i], "name", "")
                $z = IniRead($tini, $aArrays[$i], "ico", "")
                $r = IniRead($tini, $aArrays[$i], "region", "")
                ConsoleWrite($z&@CRLF)
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap2 = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled2 = _GDIPlus_ImageResize($hBitmap2, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled2)
                _GDIPlus_BitmapDispose($hBitmap_scaled2)
                _GDIPlus_BitmapDispose($hBitmap2)
                $ico = _GUIImageList_Add($hImage2, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($ListView, $hImage2, 1)
                _GUICtrlListView_AddItem($ListView, "", $ico)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $n, 1)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $r, 2)
                _GUICtrlListView_AddSubItem($ListView, $i - 1, $aArrays[$i], 3)
                $tot += 1
            Next
            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read

 

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

  • Similar Content

    • poila
      By poila
      I was reading the Helpfile on both GUICtrlRegisterListViewSort and _GUICtrlListView_SimpleSort, and after running my script, I was initially satisfied with the way columns are sorted when the user clicks on the column header.
      But at certain occasions, clicking on the column header to sort numbers - integers in particular - seem to have some unexpected behaviour.
      I cannot verify if it is due to the way I wrote the script, or because the functions used in AutoIt to sort numbers intentionally work the way they do.
      Example:
      Column ID | Item ID | Item Name | Date
      1 | ID_1 | One | 14/05/2014
      2 | ID_2 | Two| 14/05/2014
      3 | ID_3 | Three| 14/05/2014
      10 | ID_4 | Four| 14/05/2014
      9 | ID_5 | Five| 14/05/2014
      27 | ID_6 | Siz| 15/05/2014
      When the user clicks Column ID, logically the order of ascending sorting would look like this:
      1, 2, 3, 9, 10, 27
      But what I got is like this:
      1, 10, 2, 27, 3, 9
      Does anyone know the reason behind the way it is sorted this way?
      How then do I get the columns to be sorted correctly when the user clicks the column header?
      (I did read across other related threads like  and )
      I attached my codes here to see if I might write them wrongly.
      My code for generating ListView:
      $inventoryList = GUICtrlCreateListView("ID|item id|item name| Date", 45, 140, expandGUIX(750), expandGUIY(450), $LVS_REPORT, BitOR($LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE)) _GUICtrlListView_SetColumnWidth(-1, 3, 651) $hInventoryList = GUICtrlGetHandle($inventoryList) For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($inventoryList, $i, $LVSCW_AUTOSIZE_USEHEADER) Next My code for auto-resizing columns:
      Func resizeColumns($hWnd, $listView, $iColumns, $iGUI_Width, $iGUI_Height) ; Check top index - if not 0 then we have a scroll bar so increase ListView width Local $iScroll_Allowance If _GUICtrlListView_GetTopIndex($listView) > 0 Then $iScroll_Allowance = 17 EndIf ; Determine ListView width Local $iLV_Width = $iScroll_Allowance Local $iData_Width, $iHeader_Width Local $i = 0 For $i = 0 To $iColumns - 1 ; Size column to fit header _GUICtrlListView_SetColumnWidth($listView, $i, $LVSCW_AUTOSIZE_USEHEADER) $iHeader_Width = _GUICtrlListView_GetColumnWidth($listView, $i) ; Now size column to fit data _GUICtrlListView_SetColumnWidth($listView, $i, $LVSCW_AUTOSIZE) $iData_Width = _GUICtrlListView_GetColumnWidth($listView, $i) ; If header is wider, reset width If $iHeader_Width > $iData_Width Then _GUICtrlListView_SetColumnWidth($listView, $i, $iHeader_Width) $iLV_Width += $iHeader_Width Else $iLV_Width += $iData_Width EndIf Next ; Resize ListView and GUI to fit data ControlMove($hWnd, "", $listView, 10, 10, $iLV_Width + 10, $iGUI_Height - 20) ; Add 10 for internal ListView borders EndFunc ;==>resizeColumns My code for locking users from resizing columns after auto-resize:
      Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_BEGINTRACKW ; Prevent resizing Return True Case $LVN_COLUMNCLICK ; Sort column $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) $iCol = DllStructGetData($tInfo, "SubItem") _GUICtrlListView_SimpleSort($cListView, $g_bSortSense, $iCol) EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY