Sign in to follow this  
Followers 0
rasim

Get column index when click on column.

4 posts in this topic

Hi! How can get column index when click on column?

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

$hGui = GUICreate("Test", 400, 250)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems1|SubItems2", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))

$hImage = _GUIImageList_Create (16,16,5);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 3);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 11);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 22);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 33);
_GUICtrlListView_SetImageList ($hListView, $hImage, 1)

_GUICtrlListView_AddItem($hListView, "Item1",0)
_GUICtrlListView_AddItem($hListView, "Item2",2)
_GUICtrlListView_AddItem($hListView, "Item3",1)
_GUICtrlListView_AddItem($hListView, "Item4",3)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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
            ;Here code for get clicked column index
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites



Look in the help in _GUICtrlListView_Create example

BTW until you become an advanced user I would suggest using the Built-in GuiCtrlCreateListView, the UDFs will still work with the control.


SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Look in the help in _GUICtrlListView_Create example

BTW until you become an advanced user I would suggest using the Built-in GuiCtrlCreateListView, the UDFs will still work with the control.

Damn! I just unattentive! Thank you guys! :D

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

$Gui = GUICreate("Test", 400, 250)

$hListView = _GUICtrlListView_Create($GUI, "Items|SubItems1|SubItems2", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))

$hImage = _GUIImageList_Create (16,16,5);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 3);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 11);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 22);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 33);
_GUICtrlListView_SetImageList ($hListView, $hImage, 1)

_GUICtrlListView_AddItem($hListView, "Item1",0)
_GUICtrlListView_AddItem($hListView, "Item2",2)
_GUICtrlListView_AddItem($hListView, "Item3",1)
_GUICtrlListView_AddItem($hListView, "Item4",3)

_GUICtrlListView_AddSubItem ($hListView, 0,'44', 1)
_GUICtrlListView_AddSubItem ($hListView, 1,'22', 1)
_GUICtrlListView_AddSubItem ($hListView, 2,'11', 1)
_GUICtrlListView_AddSubItem ($hListView, 3,'33', 1)

_GUICtrlListView_AddSubItem ($hListView, 0,'New', 2)
_GUICtrlListView_AddSubItem ($hListView, 1,'Page', 2)
_GUICtrlListView_AddSubItem ($hListView, 2,'Sys', 2)
_GUICtrlListView_AddSubItem ($hListView, 3,'Device', 2)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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)
            Local $ColumnIndex = DllStructGetData($tInfo, "SubItem")
            MsgBox(0, "Column", "Pressed a " & $ColumnIndex & " column")
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
    EndFunc
Edited by rasim

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