Jump to content
Sign in to follow this  
badapple89

CtrlListView Get Item from last used list

Recommended Posts

badapple89

Hi guys, sure this is an easy one (maybe not)

I have a single button and two lists. When I press the button I want to get the info of the last item that was selected.

Is there any way to pass the handle of the listview with the last selected item to  _GUICtrlListView_GetSelectedIndices.

Im terrible at explaining things, so let me know if I need more clarification.

Regards

Share this post


Link to post
Share on other sites
Melba23

badapple89,

This does what you want:

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

Global $hLV_Sel

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

$cLV_1 = GUICtrlCreateListView("List 1", 10, 10, 230, 200)
For $i = 0 To 9
    GUICtrlCreateListViewItem("Item 1" & $i, $cLV_1)
Next

$cLV_2 = GUICtrlCreateListView("List 2", 260, 10, 230, 200)
For $i = 0 To 9
    GUICtrlCreateListViewItem("Item 2" & $i, $cLV_2)
Next

$cButton = GUICtrlCreateButton("Last Selected", 10, 300, 100, 30)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $iIndex = _GUICtrlListView_GetSelectedIndices($hLV_Sel)
            $sText = _GUICtrlListView_GetItemText($hLV_Sel, $iIndex)
            MsgBox($MB_SYSTEMMODAL, "Last selection", $sText)

    EndSwitch

WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate($tagNMHDR, $lParam) ; struct;hwnd hWndFrom;uint_ptr IDFrom;int Code;endstruct
    If @error Then Return
    Switch DllStructGetData($tStruct, "Code")
        Case $NM_CLICK
            $hLV_Sel = DllStructGetData($tStruct, "hWndFrom")
    EndSwitch

EndFunc
I think the code is clear enough to follow, but please do ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
badapple89

It does!

I didn't have <MsgBoxConstants.au3> though. Is this standard :S but copied the _WM_NOTIFY into my script and its working all good.

DLL stuff in AutoIt is pretty confusing, is there any good wiki's or something on it?

Also is there any documentation that contains more about the Windows Message Codes I know of the autoit help file that lists the messages and codes. But I want to know things like what $WM_NOTIFY actually IS! Guess this is more a windows question than AutoIT?

Thanks again for the help.

Share this post


Link to post
Share on other sites
mikell

For unfortunate people who prefer keep on running the last stable 3.3.8.1 instead of the beta (as it's still a beta) this $MB_SYSTEMMODAL is really a plague :)

I modestly suggest not to use it in example scripts until the beta becomes the release

Share this post


Link to post
Share on other sites
Melba23

mikell,

"Plague" is a bit strong! All we are doing is keeping guinness happy! :D

I usually use Constants.au3 in examples as that is where the constants are hidden in 3.3.8.1 but I sometime forget - I will try to do better in future. ;)

badapple89,

I recommend the GUIRegisterMsg tutorial in the Wiki if you would like to learn more about Windows messages. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mikell

mikell,

"Plague" is a bit strong! All we are doing is keeping guinness happy! :D

Oh... I'm quite able to understand this :D

Though an unknown constant *is* a true plague when the corresponding include is unfindable

Thus thank you for the info about Constants.au3 - I didn't know this

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  

×