Jump to content

Check if list view selection has changed! _GUICtrlListView_SelectionChanged


Recommended Posts

i had a major breakthrough in one of my scripts. i had to monitor list view selection changes and this might be a silly old trick for experienced people but for amateur coder, it was something great stumbled upon, thought it might be useful for people like wise.

; this will be the core.
#include <GUIListView.au3>

$CurrentMark = _GUICtrlListView_GetSelectionMark($lstView)
Func _GUICtrlListView_Selectionchanged(ByRef $CurrentMark, $LV_CtrlID)
; Author Rajesh VR , June 2009
; Checks for Mark change and returns if the selection has changed!
; requires <#include GUIListView.AU3>
; User needs to initialise $CurrentMark = _GUICtrlListView_GetSelectionMark($lstViewControl ) after the list view control is populated with items
; $currentMark initiation should be outside the monitoring loop (preferably a global variable)
; will return true if selection has changed, @extended will give selection value [extended isnt supporting | ???]
    Local $oldMark = $CurrentMark
    Local $NewMark = _GUICtrlListView_GetSelectionMark($LV_CtrlID)
    If $CurrentMark <> $NewMark Then
        $CurrentMark = $NewMark
        Return True
    Else
        Return False
    EndIf
EndFunc ;==>_GUICtrlListView_Selectionchanged

; a working demo of the UDF (shouldnt call it so yet...
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <ListBoxConstants.au3>

$frmMain = GUICreate("ListView Monitoring without WM Commands", 594, 269, 193, 125)
$iExWindowStyle = $WS_EX_CLIENTEDGE ;BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_TRACKSELECt, $LVS_EX_FLATSB)
$lstView = GUICtrlCreateListView("Column A|Column B|Column C", 12, 92, 585, 325, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($lstView, $iExListViewStyle)
GUICtrlCreateListViewItem("1|2|3", $lstView)
GUICtrlCreateListViewItem("4|5|6", $lstView)
GUICtrlCreateListViewItem("7|8|9", $lstView)

$CurrentMark = _GUICtrlListView_GetSelectionMark($lstView)

GUISetState(@SW_SHOW)
While 1 
    If _GUICtrlListView_Selectionchanged($CurrentMark, $lstView) = True Then
        ConsoleWrite(@CRLF & "Marked Row : "&  $CurrentMark & @TAB & " Selection Value " & GUIctrlREad(GuiCtrlREad($lstView)) & @cRLF)
    EndIf   
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GUICtrlListView_Selectionchanged(ByRef $CurrentMark, $LV_CtrlID)
    ; Author Rajesh VR , June 2009
    ; Checks for Mark change and returns if the selection has changed!
    ; requires <#include GUIListView.AU3>
    ; User needs to initialise $CurrentMark = _GUICtrlListView_GetSelectionMark($lstViewControl ) after the list view control is populated with items
    ; $currentMark initiation should be outside the monitoring loop (preferably a global variable)
    ; will return true if selection has changed, @extended will give selection value [extended isnt supporting | ???]
    Local $oldMark = $CurrentMark
    Local $NewMark = _GUICtrlListView_GetSelectionMark($LV_CtrlID)
    If $CurrentMark <> $NewMark Then
        $CurrentMark = $NewMark
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_GUICtrlListView_Selectionchanged
Edited by rajeshontheweb
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...