JohnOne

Handling dynamic amount of controls

5 posts in this topic

#1 ·  Posted (edited)

I get a list externally and create a load of labels and input fields to match it.

If that list is larger than the gui can handle, the controls are outside the bounds of the gui height.

Wondering what sort of control I can put them in, so user can scroll to see all the fields.

Some sort of scrollable panel would be ace, but open to any suggestions.

Here is reproducer.

#include <Array.au3>

Global $AppName = "The App"

Global $aProducts = FileReadToArray(@ScriptDir & "\Products.txt")

;_ArrayDisplay($aProducts)

_AbsentCategory($aProducts)

Func _AbsentCategory(ByRef $array)
    If UBound($array) < 1 Then
        Return
    EndIf

    $Top = 40
    Local $aControls[UBound($array)][4]

    Local $hNotFoundGUI = GUICreate($AppName & ": Products need adding", 575, 700)
    ; Labels
    GUICtrlCreateLabel("Product name", 15, 10, 100)
    GUICtrlCreateLabel("Category 1", 240, 10, 100)
    GUICtrlCreateLabel("Category 2", 410, 10, 100)

    Local $hNotFounButtonOK = GUICtrlCreateButton("Done", 15, 670, 60)

    ; Create an array of contrils with the backup array as text
    For $y = 0 To UBound($array) - 1
        GUICtrlCreateLabel($array[$y], 15, $Top, 210, 20)
        $aControls[$y][0] = GUICtrlCreateInput("", 240, $Top, 150) ; cat 1
        $aControls[$y][1] = GUICtrlCreateInput("", 410, $Top, 150) ; cat 2
        $Top += 30
    Next

    GUISetState()
    Sleep(5000)

    While GUIGetMsg() <> $hNotFounButtonOK
    WEnd

    ; Not finished yet
    ; Check all fields are filled before proceding
    Do
    Until _Checkfields($aControls)

    ; Update array
    For $i = 0 To UBound($array) - 1
        $array[$i][1] = GUICtrlRead($aControls[$i][0])
        $array[$i][2] = GUICtrlRead($aControls[$i][1])
    Next

EndFunc   ;==>_AbsentCategory

Func _Checkfields(ByRef $array)
    For $i = 0 To UBound($array) - 1
        If GUICtrlRead($array[$i][0]) = "" Or GUICtrlRead($array[$i][1]) = "" Then
            MsgBox(4096 + 48, $AppName & ": - Warning", "Fill all fields" & @CRLF & "and press OK")
            Return 0
        EndIf
    Next
    Return 1
EndFunc   ;==>_Checkfields

Here is Products.txt

Product1
Product2
Product3
Product4
Product5
Product6
Product7
Product8
Product9
Product10
Product11
Product12
Product13
Product14
Product15
Product16
Product17
Product18
Product19
Product20
Product21
Product22
Product23
Product24
Product25
Product26
Product27
Product28
Product29
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe overly complicated, but you can create a listview and only one edit and label...make the label and edit disabled until a listview item is selected...populate the label, and allow user to add data to the edit...add a button to submit the number to the listview, update the listview, and clear out the edit and label plus make disabled again.

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

JohnOne,

Look at my Scrollbars UDF - GUIScrollbars_Size_Example_2 shows you how to do what you want. :)

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

Sweet, cheers M23. way simpler than Listview..... On the outside :)

#include <Array.au3>
#include <GUIScrollbars_Ex.au3>

Global $AppName = "The App"

Global $aProducts = FileReadToArray(@ScriptDir & "\Products.txt")

;_ArrayDisplay($aProducts)

_AbsentCategory($aProducts)

Func _AbsentCategory(ByRef $array)
    If UBound($array) < 1 Then
        Return
    EndIf

    $Top = 40
    Local $aControls[UBound($array)][4]

    Local $hNotFoundGUI = GUICreate($AppName & ": Products without categories", 575, 700)
    ; Labels
    GUICtrlCreateLabel("Product name", 15, 10, 100)
    GUICtrlCreateLabel("Category 1", 240, 10, 100)
    GUICtrlCreateLabel("Category 2", 410, 10, 100)

    ;Local $hNotFounButtonOK = GUICtrlCreateButton("Done", 15, 670, 60)

    ; Create an array of contrils with the backup array as text
    For $y = 0 To UBound($array) - 1
        GUICtrlCreateLabel($array[$y], 15, $Top, 210, 20)
        $aControls[$y][0] = GUICtrlCreateInput("", 240, $Top, 150) ; cat 1
        $aControls[$y][1] = GUICtrlCreateInput("", 410, $Top, 150) ; cat 2
        $Top += 30
    Next

    Local $hNotFounButtonOK = GUICtrlCreateButton("Done", 15, $Top - 5, 60)
    
    _GUIScrollbars_Generate($hNotFoundGUI, 570, $Top + 10)

    GUISetState()
    Sleep(5000)

    While GUIGetMsg() <> $hNotFounButtonOK
    WEnd

    ; Not finished yet
    ; Check all fields are filled before proceding
    Do
    Until _Checkfields($aControls)

    ; Update array
    For $i = 0 To UBound($array) - 1
        $array[$i][1] = GUICtrlRead($aControls[$i][0])
        $array[$i][2] = GUICtrlRead($aControls[$i][1])
    Next

EndFunc   ;==>_AbsentCategory

Func _Checkfields(ByRef $array)
    For $i = 0 To UBound($array) - 1
        If GUICtrlRead($array[$i][0]) = "" Or GUICtrlRead($array[$i][1]) = "" Then
            MsgBox(4096 + 48, $AppName & ": - Warning", "Fill all fields" & @CRLF & "and press OK")
            Return 0
        EndIf
    Next
    Return 1
EndFunc   ;==>_Checkfields

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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