Jump to content

How to return array's current row?


qwert
 Share

Recommended Posts

I don't work with arrays all that often, so please excuse my asking what might be a basic question.

Based on a "root filename", I use the _FileListToArrayRec to locate possible sources of a useful graphic ... which often has several file choices, as shown by the example below.

I can envision a couple of ways to prompt the user (with a dialog) to make a selection, based on found files.

But is there a direct way to know the row the user has clicked on?

Thanks in advance for any help.

 

Selected Row.PNG

Link to comment
Share on other sites

make your own listview (as I don't think you can do anything with _arraydisplay's listview) and hunt things about selecting its rows?

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Alternatively you could use a ComboBox for example:

#include <Array.au3>
#include <ComboConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $sFolderPath = @ScriptDir
    Local $aFolderPath = _FileListToArrayRec($sFolderPath, '*.ai;*.eps;*.jpg;*.gif;*.png', 1, 1, 0, 1)
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a combobox control.
    Local $idComboBox = GUICtrlCreateCombo("Please Select an Image", 10, 10, 185, 20, $CBS_DROPDOWNLIST)
    Local $idSelect = GUICtrlCreateButton("Select", 200, 9, 90, 23)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Add additional items to the combobox.
    GUICtrlSetData($idComboBox, _ArrayToString($aFolderPath, '|', 1))

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $sComboRead = ""

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop
            Case $idSelect
                If FileExists($sFolderPath & '\' & GUICtrlRead($idComboBox)) Then
                    ShellExecute($sFolderPath & '\' & GUICtrlRead($idComboBox))
                EndIf
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Well, after what I can only describe as a learning experience, I opted to use AddItem.  (AddArray turned into a confusing exercise of trying to use the indices right in the arrays.)  The following statements worked ... and I ended up with a very sensible, scrollable panel of found files.

If IsArray($array) Then
    For $i = 1 to $array[0] Step 1
    _GUICtrlListView_AddItem($ListView, $array[$i])
    Next
EndIf

The combo box method will be a handy alternative.

Thanks for both responses.

 

Link to comment
Share on other sites

From the Help file about _ArrayDisplay:

Run User Func
Run the user-defined function passed in $hUser_Function. This function is entirely separate from the UDF and must be created and coded by the user to accept 2 (and only 2) parameters which will be provided by the UDF itself: the full array being displayed and a 1D array holding the selected rows indices with a count in the [0] element. These parameters can then be used inside the user function as required. The button is not displayed if no function is specified.

And the code:

#include <Array.au3>

Global $aSelRows
Global $aArray[10][6]
For $i = 0 To 9
  For $j = 0 To 5
    $aArray[$i][$j] = $i & "/" & $j
  Next
Next
_ArrayDisplay( $aArray, "Select one/more items. Click ""Run User Func""", "", 0, Default, Default, Default, Default, GetSelected )

Func GetSelected( $aArray, $aSelected )
  $aSelRows = $aSelected
  If $aSelRows[0] = 0 Then
    MsgBox( 0, "", "Select one/more items. Click ""Run User Func""" )
  Else
    MsgBox( 0, "", $aSelRows[0] & " items selected" )
    Send( "{ESC}" )
  EndIf
EndFunc

_ArrayDisplay( $aSelRows )

 

Link to comment
Share on other sites

@LarsJ: Thanks for reminding me of that method. I recall using something similar 4 or 5 years ago. I'm sure it will come in handy, again.  But for now, I'm firmly on the ListView track for this project ... and learning more every day.

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