Jump to content

Arrow in Column (Listview)


Madza91
 Share

Recommended Posts

Hello, I need to put "arrow" in Column title when is column clicked... like in ScreenShot:

Posted Image

I know to detect when is Column Clicked , put I don't know to show that arrow (who shows sort direction)

Can someone help me to made this? :D

Here is script with detection ColumnClick and sorting:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $hListView, $B_DESCENDING

_Main()

Func _Main()

    GUICreate("ListView SimpleSort", 400, 300)

    $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
    GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    GUICtrlCreateListViewItem("line4|5|more_a", $hListView)

    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $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 ; A column was clicked
                    MsgBox(0,"ColumnClick", "Column is clicked.")
                    _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Authenticity, thank you :D

I solved it :D

Zedna, your LogView is nice :o

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Hello again... I found some bug with "_GUICtrlListView_InsertItem" Func.

When I use "GUICtrlCreateListViewItem" for adding items in ListView, then Sorting works, but when add items with "_GUICtrlListView_InsertItem" then Sord don't work... Why?

Here is example script: (Funcs for adding items is Line 13/14)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hListView

    GUICreate("ListView Sort", 300, 200)
    $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180)
    For $a = 0 To 3
;~      GUICtrlCreateListViewItem("Line " & $a + 4, $hListView)
        _GUICtrlListView_InsertItem($hListView, "Line " & $a)
    Next
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    _GUICtrlListView_RegisterSortCallBack($hListView)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($hListView)
    GUIDelete()

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hListView

    GUICreate("ListView Sort", 300, 200)
    $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180)
    For $a = 0 To 3
;~   GUICtrlCreateListViewItem("Line " & $a + 4, $hListView)
        _GUICtrlListView_InsertItem($hListView, "Line " & $a, -1, -1,  _GUICtrlListView_GetItemCount($hListView) + 9999)
    Next
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    _GUICtrlListView_RegisterSortCallBack($hListView)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($hListView)
    GUIDelete()

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 3 months later...

I was looking for the same thing as n3nE was.

The arrows appear fine with the _GuiCtrlListView_SortItems() function, but my first column (column #0) are all dates formatted dd-MM-yyyy and sorting with _GuiCtrlListView_SortItems() doesn't sort the dates right (as expected). So I created a column (column #11) that I made invisible with columwidth=0 and populated that column with the date formatted yyyyMMdd, which does sort correctly and "routed" the click on header #0 with the following code:

Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
Local $index = DllStructGetData($tInfo, "SubItem")
If $index = 0 Then $index = UBound($aDBMain, 2) - 1
_GUICtrlListView_SortItems(GUICtrlGetHandle($LV_Main), $index)

This works fine, but as expected no arrows show up when sorting (since they're drawn on column #11, which is sorted and invisible, instead of column #0).

I took a look at Zedna's Log_View project and love his custom sorting arrows. I don't understand the code though, since I know nothing about DLLStruct functions (the ones in my code are copied from the helpfile).

Could somebody maybe explain a bit more clear how Zedna achieves to show those awesome icons?

Edited by Cusem
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...