Sign in to follow this  
Followers 0
Pook

Get selected (highlighted) Item In ListView

6 posts in this topic

Okay, I've been looking in the Help file at all the GUICtrlListView_GetItem /GetItemChecked / ClickItem and so on.

What I'm trying to do is get the highlighted item in the listview to use in other functions.

For Example:

I'm making a GUI to Edit an INI file. The GUI show all the Free Spots in the INI file that you can add something to. But I can't get the function to read what item in the list is highlighted.

** Attached Screenshot

post-20189-0-76869200-1325793215_thumb.p

Any Idea.. I know I'm just missing it in the help-file, or I just don't understand what I'm reading.

Share this post


Link to post
Share on other sites



Pook,

Is this a native or UDF created ListView? :)

If native, then GUICtrlRead should work.

If UDF, then use _GUICtrlListView_GetSelectedIndices.

Post some simple reproducer code if you still have problems. ;)

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

Tried both the examples in the Help file. Still not sure what I'm missing.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3> ; Added to Master script
#include <GuiImageList.au3> ; Added to Master script
#include <GuiListView.au3> ; Added to Master script
Global $hListView ; List ViewName
_GUIBOX()

Func _GUIBOX()
$FormAR1 =   GUICreate("TEST -", 737, 449, 192, 114)
$RemoveButton3 =  GUICtrlCreateButton("GO", 472, 397, 105, 33)
$ButtonExit =  GUICtrlCreateButton("Exit", 615, 398, 113, 33)
_Add_RemoveListview() ; Build List View

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE   ; Exit Top buttom
            Exit
         Case $ButtonExit      ; Exit Button
          Exit
         Case $RemoveButton3    ; Remove Button
         _AddAppINI()
    EndSwitch
WEnd
Endfunc

Func _Add_RemoveListview() ; Fucntion to list INI applicaton Information
Local $hImage, $hListView
$hListView = GUICtrlCreateListView("", 435, 31, 300, 337)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
; Load images
$hImage = _GUIImageList_Create() ;1 = Green 1 = red 2 = Blue
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x0000FF, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF6600, 16, 16))
_GUICtrlListView_SetImageList($hListView, $hImage, 1) ;0 = Green 1 = red 2 = Blue
; Add columns
_GUICtrlListView_AddColumn($hListView, "App #", 65)
_GUICtrlListView_AddColumn($hListView, "App Name", 300)
;/////////////////////////////////////////////////
; Load INI Information in ListView  (removed Loop from INI File)
;/////////////////////////////////////////////////
    _GUICtrlListView_AddItem($hListView, "App1", 1)
  _GUICtrlListView_AddSubItem($hListView, 0, "< Free Spot >", 1)
  _GUICtrlListView_AddItem($hListView, "App2", 1)
  _GUICtrlListView_AddSubItem($hListView, 1, "< Free Spot >", 1)
  _GUICtrlListView_AddItem($hListView, "App3", 2)
  _GUICtrlListView_AddSubItem($hListView, 2, "OFFICE", 1)
;/////////////////////////////////////////////////
; Load Grouping Information in ListView
;/////////////////////////////////////////////////
; Build groups
_GUICtrlListView_EnableGroupView($hListView)
_GUICtrlListView_InsertGroup($hListView, -1, 1, "Software Group 1")
_GUICtrlListView_InsertGroup($hListView, -1, 2, "Software Group 2")
_GUICtrlListView_InsertGroup($hListView, -1, 3, "Software Group 3")
_GUICtrlListView_InsertGroup($hListView, -1, 4, "Software Group 4")
_GUICtrlListView_InsertGroup($hListView, -1, 5, "End Tasks")

; Add Software Group 1
  For $Y = 0 To 17
_GUICtrlListView_SetItemGroupID($hListView, $Y, 1)
next
; Add Software Group 2
  For $Y = 18 To 36
_GUICtrlListView_SetItemGroupID($hListView, $Y, 2)
next
; Add Software Group 3
  For $Y = 37 To 55
_GUICtrlListView_SetItemGroupID($hListView, $Y, 3)
next
; Add Software Group 4
  For $Y = 56 To 74
_GUICtrlListView_SetItemGroupID($hListView, $Y, 4)
next
; Add Software Group 5 (End task)
  For $Y = 75 To 87
_GUICtrlListView_SetItemGroupID($hListView, $Y, 5)
next


EndFunc   ;==>_Main
Func _AddAppINI()
;/////////////////////////////////////////////////
; Read all Inputs on Form
;/////////////////////////////////////////////////
MsgBox(4160, "TEST", "Selected Item from List is: " & _GUICtrlListView_GetSelectedIndices($hListView))
endfunc

Share this post


Link to post
Share on other sites

Pook,

Declaring $hlistview as Local inside function _Add_RemoveListview means that the Global variable of the same name does not get updated - hence you get no response in function AddAppINI. :)

Also, you should match UDF ListView and ListViewitem creation functions - mixing them usually ends in tears somewhere along the line. :D

Finally, _GUICtrlListView_GetSelectedIndices returns an array unless you tell it not to - read the Help file. :)

This works for me:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3> ; Added to Master script
#include <GuiImageList.au3> ; Added to Master script
#include <GuiListView.au3> ; Added to Master script
Global $hListView ; List ViewName
_GUIBOX()

Func _GUIBOX()
$FormAR1 =   GUICreate("TEST -", 737, 449, 192, 114)
$RemoveButton3 =  GUICtrlCreateButton("GO", 472, 397, 105, 33)
$ButtonExit =  GUICtrlCreateButton("Exit", 615, 398, 113, 33)
_Add_RemoveListview($FormAR1) ; Build List View

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE   ; Exit Top buttom
            Exit
         Case $ButtonExit     ; Exit Button
          Exit
         Case $RemoveButton3    ; Remove Button
         _AddAppINI()
    EndSwitch
WEnd
Endfunc

Func _Add_RemoveListview($FormAR1) ; Fucntion to list INI applicaton Information
Local $hImage
$hListView = _GUICtrlListView_Create($FormAR1, "", 435, 31, 300, 337)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
; Load images
$hImage = _GUIImageList_Create() ;1 = Green 1 = red 2 = Blue
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x0000FF, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF6600, 16, 16))
_GUICtrlListView_SetImageList($hListView, $hImage, 1) ;0 = Green 1 = red 2 = Blue
; Add columns
_GUICtrlListView_AddColumn($hListView, "App #", 65)
_GUICtrlListView_AddColumn($hListView, "App Name", 300)
;/////////////////////////////////////////////////
; Load INI Information in ListView  (removed Loop from INI File)
;/////////////////////////////////////////////////
    _GUICtrlListView_AddItem($hListView, "App1", 1)
  _GUICtrlListView_AddSubItem($hListView, 0, "< Free Spot >", 1)
  _GUICtrlListView_AddItem($hListView, "App2", 1)
  _GUICtrlListView_AddSubItem($hListView, 1, "< Free Spot >", 1)
  _GUICtrlListView_AddItem($hListView, "App3", 2)
  _GUICtrlListView_AddSubItem($hListView, 2, "OFFICE", 1)
;/////////////////////////////////////////////////
; Load Grouping Information in ListView
;/////////////////////////////////////////////////
; Build groups
_GUICtrlListView_EnableGroupView($hListView)
_GUICtrlListView_InsertGroup($hListView, -1, 1, "Software Group 1")
_GUICtrlListView_InsertGroup($hListView, -1, 2, "Software Group 2")
_GUICtrlListView_InsertGroup($hListView, -1, 3, "Software Group 3")
_GUICtrlListView_InsertGroup($hListView, -1, 4, "Software Group 4")
_GUICtrlListView_InsertGroup($hListView, -1, 5, "End Tasks")

; Add Software Group 1
  For $Y = 0 To 17
_GUICtrlListView_SetItemGroupID($hListView, $Y, 1)
next
; Add Software Group 2
  For $Y = 18 To 36
_GUICtrlListView_SetItemGroupID($hListView, $Y, 2)
next
; Add Software Group 3
  For $Y = 37 To 55
_GUICtrlListView_SetItemGroupID($hListView, $Y, 3)
next
; Add Software Group 4
  For $Y = 56 To 74
_GUICtrlListView_SetItemGroupID($hListView, $Y, 4)
next
; Add Software Group 5 (End task)
  For $Y = 75 To 87
_GUICtrlListView_SetItemGroupID($hListView, $Y, 5)
next


EndFunc   ;==>_Main
Func _AddAppINI()
;/////////////////////////////////////////////////
; Read all Inputs on Form
;/////////////////////////////////////////////////
MsgBox(4160, "TEST", "Selected Item from List is: " & _GUICtrlListView_GetSelectedIndices($hListView, False))
endfunc

All clear? Please ask if not. ;)

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

Wow.. something that looks so simple just killed 5 hours of my time. :) I'm guessing the local part kept all the other things I tried from working. Also thanks for the code idea. I'll clean it up to make sure I'm using the functions from the UDF.

Share this post


Link to post
Share on other sites

Pook,

something that looks so simple just killed 5 hours of my time

So often the case! ;)

Glad I could help. :)

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

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