Jump to content

List View Function Call


BSoft
 Share

Recommended Posts

Hi, I have a ListView that is populated with various text objects and I want to call a function of my own each time the selected item in the ListView changes.

If anyone can give me some advice I would appreciate it very much.

Thank you!

Link to comment
Share on other sites

  • Moderators

BSoft,

How is your ListView populated? Can you not run your function each time the ListView is redrawn?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Maybe I can do that. But I don't know how to capture the redraw message for the List View. I was wondering if there might be a message that is able to be captured for a change in selection of the current Item (row) in the List View but I am un sure how to do this. Are there any examples that might do something similar?

Link to comment
Share on other sites

  • Moderators

BSoft,

Sorry, I misread the OP - I thought you wanted to detect a change in content, not selection. Try this:

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

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Column 0|Column 1|Column 2", 10, 10, 300, 300)
For $i = 0 To 9
    GUICtrlCreateListViewItem("Item " & $i & "- 0|SubItem " & $i & "- 1|SubItem " & $i & "- 2", $cLV)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd



Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If @error Or DllStructGetData($tNMHDR, "IDFrom") <> $cLV Then Return
    Local $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
    Switch DllStructGetData($tNMHDR, "Code")
        Case $NM_CLICK
            ConsoleWrite("Row: " & DllStructGetData($tNMLISTVIEW, "Item") & " - Col: " & DllStructGetData($tNMLISTVIEW, "SubItem") & @CRLF)
    EndSwitch
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

BSoft,

My pleasure - sorry for the earlier misunderstanding.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

BSoft,

Sorry, busy day flying - I will reply in more detail tomorrow.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

BSoft,

Something like this should cover both mouse clicks and arrow keys::

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIListView.au3>

Global $iSelected = -1

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Column 0|Column 1|Column 2", 10, 10, 300, 300)
For $i = 0 To 9
    GUICtrlCreateListViewItem("Item " & $i & "-0|SubItem " & $i & "-1|SubItem " & $i & "-2", $cLV)
Next

; Dummy control to fire if mouseclick or key action detected within the ListView

$cLV_Dummy = GUICtrlCreateDummy()

$cCombo = GUICtrlCreateCombo("", 380, 10, 100, 20)
GUICtrlSetData($cCombo, "0|1|2|3|4|5|6|7|8|9")

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cLV_Dummy
            $iCurrent = _GUICtrlListView_GetSelectedIndices($cLV)
            If $iCurrent <> $iSelected Then
                $iSelected = $iCurrent

                MsgBox($MB_SYSTEMMODAL, "ListView Selection", "Row: " & $iSelected)
            EndIf

    EndSwitch

WEnd



Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If @error Or DllStructGetData($tNMHDR, "IDFrom") <> $cLV Then Return
    Local $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
    Switch DllStructGetData($tNMHDR, "Code")
        ; Look for mouseclick or key action within the ListView

        Case $NM_CLICK, $LVN_KEYDOWN
            ; Fire the dummy control
            GUICtrlSendToDummy($cLV_Dummy)
    EndSwitch
EndFunc

I have included the combo so that you can see that arrow key movements there do not fire the dummy - only arrow keys within the ListView itself.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

BSoft,

I changed M23's example a little to add clarity (for myself, if no one else - apologies to M23 for impertinence, if required).  I expanded comments to try to clarify what is happening for notification message $LVN_KEYDOWN and changed the way the messages are displayed.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIListView.au3>
#include <EditConstants.au3>

Global $iSelected = ""  ;   changed to match return type from _GUICtrlListView_GetSelectedIndices($cLV) (string)

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Column 0      |Column 1|Column 2", 10, 10, 230, 200)  ;   Allow single selection only (default)
For $i = 0 To 9
    GUICtrlCreateListViewItem(Chr(65 + $i) & " - Item " & $i & "-0|SubItem " & $i & "-1|SubItem " & $i & "-2", $cLV)
Next

; Dummy control to fire if mouseclick or key action detected within the ListView

$cLV_Dummy = GUICtrlCreateDummy()

$cCombo = GUICtrlCreateCombo("", 310, 10, 100, 20)
GUICtrlSetData($cCombo, "0|1|2|3|4|5|6|7|8|9")

; Area to display Control info when selected
$cDebug = GUICtrlCreateEdit('', 10, 250, 480, 230, BitOR($ES_READONLY, $WS_VSCROLL))

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cLV_Dummy
            $iCurrent = _GUICtrlListView_GetSelectedIndices($cLV)   ; return string by default
            If $iCurrent <> $iSelected Then
                $iSelected = $iCurrent

                GUICtrlSetData($cDebug, "ListView Selection Row: " & $iSelected & @CRLF, 1)
            EndIf

        Case $cCombo

            GUICtrlSetData($cDebug, "Combo Selection: " & guictrlread($cCombo) & @CRLF, 1)
    EndSwitch

WEnd



Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    ; return if
    ;      there was an error creating the notification message header structure or
    ;      the notification message is NOT from our listview ($cLV)
    If @error Or DllStructGetData($tNMHDR, "IDFrom") <> $cLV Then Return

    Local $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
    Switch DllStructGetData($tNMHDR, "Code")

        ; Look for mouseclick or key action within the ListView

        ;   Valid keys seem to be:
        ;       left/right/up/down arrows
        ;       page up/down
        ;       key matching the first char of any row

        Case $NM_CLICK, $LVN_KEYDOWN
            ; Fire the dummy control
            GUICtrlSendToDummy($cLV_Dummy)
    EndSwitch

EndFunc   ;==>_WM_NOTIFY

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

kylomas,

No problem at all - and you have provided some nice new information (the limited number of recognised keys within the ListView) for which I am most grateful.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...