JustSomeone Posted December 30, 2016 Posted December 30, 2016 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 . I need to make the "<<" button works aswell, but looking at the _ButtonAdd() function i start to think of suicide. Please help expandcollapse popup#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
Moderators Melba23 Posted December 30, 2016 Moderators Posted December 30, 2016 (edited) JustSomeone, How about this: expandcollapse popup#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 December 30, 2016 by Melba23 JustSomeone 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JustSomeone Posted December 30, 2016 Author Posted December 30, 2016 Awesome, thanks. Edited it a bit so i can click the >> or << button without selecting and it works too (adds the first value from the list)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now