Jump to content

can _GUICtrlListView_GetSelectedIndices distinguish between selected or not?


Go to solution Solved by Melba23,

Recommended Posts

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!

Link to comment
Share on other sites

  • Moderators
  • Solution

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

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

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!

Link to comment
Share on other sites

  • Moderators

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

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