MuffettsMan

can _GUICtrlListView_GetSelectedIndices distinguish between selected or not?

6 posts in this topic

running the following code on a listview that has nothing selected:

$selectedRow = _GUICtrlListView_GetSelectedIndices($GUI_BackupQueueListView) ; return the selected row
      ConsoleWriteGUI("$selectedRow ID: " & $selectedRow & @CRLF)

      $rowID = _GUICtrlListView_GetItemText($GUI_BackupQueueListView, Number($selectedRow), 0)
      $rowName = _GUICtrlListView_GetItemText($GUI_BackupQueueListView, Number($selectedRow), 1)
      ConsoleWriteGUI("ID: " & $rowID & " Name: " & $rowName & @CRLF)

i was hoping it would error or something but it returns the first value in the list (which when the script loads nothing is selected)

is there a way to distinguish if something is selected or not?


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites



so basically, how can i tell if the first row is selected or no row is selected?


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites

MuffettsMan,

You need to check the returned value from the function. If using the default string return, you get an empty string if nothing is selected - if using the array return, the [0] element gives the count of selected items. This works fine for me: :)

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

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

$cLV = GUICtrlCreateListView("Column", 10, 10, 200, 200)
For $i = 0 To 9
    GUICtrlCreateListViewItem("Item " & $i, $cLV)
Next

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

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $sSel = _GUICtrlListView_GetSelectedIndices($cLV)
            MsgBox($MB_SYSTEMMODAL, "Selected", "-" & $sSel & "-") ; shows when return is an empty string

            $aSel = _GUICtrlListView_GetSelectedIndices($cLV, True)
            MsgBox($MB_SYSTEMMODAL, "Selected count", $aSel[0]) ; Shows count of selected items
    EndSwitch
WEnd
All this is clearly explained in the Help file. ;)

M23

1 person likes this

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

#4 ·  Posted (edited)

Thx Melba,  I think the definition of clearly starts to degrade when you don't know what you are doing :D  - I must have jacked up when using Number($selectedRow) instead $selectedRow[0] like I should have been using looking at it now i don't know what i was thinking >_<

 

Edit:

blaugh i think i get it... the code was doing what i said not what i meant....  when i did the number($var) of a null it prob just sets it to 0 - no where did i actually check to see if it was legit /sigh

Edited by MuffettsMan

Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites

MuffettsMan,

 

the code was doing what i said not what i meant

Yup, always annoying when the code refuses to read your mind and just executes exactly what you told it to do. :D

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

autoit feature / enhancement request - mind reader UDF... aka the birth of skynet!


Don't let that status fool you, I am no advanced memeber!

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