Jump to content

Two combos and buttons to move values between


JustSomeone
 Share

Recommended Posts

Hola amigos,

I am having a nightmare with two combo boxes, and two buttons << and >> to move data  between them. If someone ever did such thing, can i get some help, because the more i write it , the more i understand i'm doing it wrong.

I made some small example (copy-pasted some stuff, ignore the variable namings) so i can show what i need. Example is working one

I'm having an 2d array, containing the data i need , and using the method below to set it in the combo box. So far the ">>" button works, but i'm 100% sure this is some good example how bad i am at programming :D . I need to make the "<<" button works aswell, but looking at the _ButtonAdd() function i start to think of suicide. 

Please help :D

#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $aListControllers[5][2] = [["01", "Door1"], ["02", "Door2"], ["03", "Door3"], ["04", "akhsd"], ["05", "asshd"]]

;Stripped GUI example
#Region ### START Koda GUI section ###
$Form1 = GUICreate("test", 551, 273, 274, 218)
$controllerlist = GUICtrlCreateList("", 233, 10, 113, 190, BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL), $WS_EX_CLIENTEDGE)
$buttonadd = GUICtrlCreateButton(">>", 374, 69, 27, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$buttonremove = GUICtrlCreateButton("<<", 374, 101, 27, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$userlist = GUICtrlCreateList("", 418, 10, 113, 190, BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL), $WS_EX_CLIENTEDGE)
$savebutton = GUICtrlCreateButton("Save", 320, 224, 75, 25)
$cancelbutton = GUICtrlCreateButton("Cancel", 408, 224, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $a = ""
For $x = 0 To UBound($aListControllers, 1) - 1 Step 1
    $a &= $aListControllers[$x][0] & "-" & $aListControllers[$x][1] & "|"
Next
GUICtrlSetData($controllerlist, $a)
GUICtrlSetData($userlist, "")

;striped func just for the example
Func _ButtonAdd()
    Local $aSelectedValue = GUICtrlRead($controllerlist, $GUI_READ_EXTENDED)
    If StringInStr($aSelectedValue, "-", 2) > 0 Then
        $aSplitedValue = StringSplit($aSelectedValue, "-")
        $b = _ArraySearch($aListControllers, $aSplitedValue[2])
        _ArrayDelete($aListControllers, $b)
        Local $a = ""
        For $x = 0 To UBound($aListControllers, 1) - 1
            $a &= $aListControllers[$x][0] & "-" & $aListControllers[$x][1] & "|"
        Next
        GUICtrlSetData($controllerlist, "")
        GUICtrlSetData($controllerlist, $a)
        GUICtrlSetData($userlist, $aSelectedValue)
    Else
        Return
    EndIf
EndFunc   ;==>_ButtonAdd

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $cancelbutton, $savebutton
            Exit

        Case $buttonadd
            _ButtonAdd()
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Moderators

JustSomeone,

How about this:

#include <GUIConstantsEx.au3>
#include <Array.au3>

Global $aListControllers[5][2] = [["01", "Door1"], ["02", "Door2"], ["03", "Door3"], ["04", "akhsd"], ["05", "asshd"]]
Global $aListUser[0][2]

$Form1 = GUICreate("test", 551, 273, 274, 218)

$controllerlist = GUICtrlCreateList("", 233, 10, 113, 190);, BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL), $WS_EX_CLIENTEDGE)
$userlist = GUICtrlCreateList("", 418, 10, 113, 190);, BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL), $WS_EX_CLIENTEDGE)

$buttonadd = GUICtrlCreateButton(">>", 374, 69, 27, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$buttonremove = GUICtrlCreateButton("<<", 374, 101, 27, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$savebutton = GUICtrlCreateButton("Save", 320, 224, 75, 25)
$cancelbutton = GUICtrlCreateButton("Cancel", 408, 224, 75, 25)

GUISetState(@SW_SHOW)

_LoadLists()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $cancelbutton, $savebutton
            Exit

        Case $buttonadd
            _ButtonAdd()

        Case $buttonremove
            _ButtonRemove()
    EndSwitch
WEnd

;striped func just for the example
Func _ButtonAdd()
    Local $aSelectedValue = GUICtrlRead($controllerlist);, $GUI_READ_EXTENDED)
    If StringInStr($aSelectedValue, "-", 2) Then ; > 0 Then
        $aSplitedValue = StringSplit($aSelectedValue, "-")
        $b = _ArraySearch($aListControllers, $aSplitedValue[2])
        _ArrayDelete($aListControllers, $b)
        _ArrayAdd($aListUser, $aSplitedValue[1] & "|" & $aSplitedValue[2])
        _LoadLists()
    EndIf
EndFunc   ;==>_ButtonAdd

Func _ButtonRemove()
    Local $aSelectedValue = GUICtrlRead($userlist);, $GUI_READ_EXTENDED)
    If StringInStr($aSelectedValue, "-", 2) Then ; > 0 Then
        $aSplitedValue = StringSplit($aSelectedValue, "-")
        $b = _ArraySearch($aListUser, $aSplitedValue[2])
        _ArrayDelete($aListUser, $b)
        _ArrayAdd($aListControllers, $aSplitedValue[1] & "|" & $aSplitedValue[2])
        _LoadLists()
    EndIf
EndFunc   ;==>_ButtonAdd


Func _LoadLists()

    Local $a = "|" ; This forces a replace of the existing data when you set it later
    For $x = 0 To UBound($aListControllers, 1) - 1 Step 1
        $a &= $aListControllers[$x][0] & "-" & $aListControllers[$x][1] & "|"
    Next
    GUICtrlSetData($controllerlist, $a)
    $a = "|"
    For $x = 0 To UBound($aListUser, 1) - 1 Step 1
        $a &= $aListUser[$x][0] & "-" & $aListUser[$x][1] & "|"
    Next
    GUICtrlSetData($userlist, $a)

EndFunc

M23

Edit: And they are lists, not combos.

Edited by Melba23

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