BSoft Posted July 21, 2015 Posted July 21, 2015 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!
Moderators Melba23 Posted July 21, 2015 Moderators Posted July 21, 2015 BSoft,How is your ListView populated? Can you not run your function each time the ListView is redrawn?M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BSoft Posted July 21, 2015 Author Posted July 21, 2015 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?
Moderators Melba23 Posted July 21, 2015 Moderators Posted July 21, 2015 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 EndFuncM23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BSoft Posted July 21, 2015 Author Posted July 21, 2015 Ok that looks like it will do the things I need. Thank you so much. Really appreciated.
Moderators Melba23 Posted July 21, 2015 Moderators Posted July 21, 2015 BSoft,My pleasure - sorry for the earlier misunderstanding.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BSoft Posted July 21, 2015 Author Posted July 21, 2015 Actually, when I try this sample code it works as expected - can I ask further however, how can I also get it to work when I change the selection using the up/down arrow keys?
Moderators Melba23 Posted July 22, 2015 Moderators Posted July 22, 2015 BSoft,Sorry, busy day flying - I will reply in more detail tomorrow.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted July 23, 2015 Moderators Posted July 23, 2015 BSoft,Something like this should cover both mouse clicks and arrow keys::expandcollapse popup#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 EndFuncI 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
kylomas Posted July 24, 2015 Posted July 24, 2015 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.expandcollapse popup#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_NOTIFYkylomas 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
Moderators Melba23 Posted July 24, 2015 Moderators Posted July 24, 2015 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BSoft Posted July 25, 2015 Author Posted July 25, 2015 Once again thank you very much for you help! This is very helpful.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now