Slhama Posted January 24, 2021 Share Posted January 24, 2021 Hello guys, I've just encountered a very sneaky problem : I have a combobox where users can select a department and, following, a 2nd combobox which content change according to the first choice. Case $ComboService ;Dpt choice GUICtrlSetData($ComboCatN1,"") ;Reset Combo GUICtrlSetData($ComboCatN2,"") ;Reset Combo Global $Grp = GUICtrlRead($ComboService) $Ini = @AppDataDir & "\GLPI\" & $Grp ;path to ini file $array_N1 = IniReadSectionNames($Ini) ;read sections For $i = 1 To $array_N1[0] $N1 &= "|" & $array_N1[$i] Next GUICtrlSetData($ComboCatN1, $N1) ;Populate combo It works great but... When I choose something in my first combo ($ComboService) and something in the second one ($ComboCatN1) and then I choose something new in the first one, the second combo repopulates but adds the previous selection. Exemple : if my 2nd combo contains "Cat.A ; Cat.B ; Cat.C", if I select "Cat.B" then change the selection in my first combo, my 2nd combo will be "Cat.B ; Cat.A ; Cat.B ; Cat.C". I also tried with _GUICtrlComboBox_SetCurSel($ComboCatN1, -1) but with no more success... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 24, 2021 Moderators Share Posted January 24, 2021 Slhama, Welcome to the AutoIt forums. You need to add a separator character to the start of the new data - then, as explained in the Help file, it will replace the existing content in the combo: Quote For Combo or List control : If the "data" corresponds to an already existing entry it is set as the default. If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed. A trailing GUIDataSeparatorChar is ignored. M23 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 Link to comment Share on other sites More sharing options...
Slhama Posted January 24, 2021 Author Share Posted January 24, 2021 2 hours ago, Melba23 said: Slhama, Welcome to the AutoIt forums. You need to add a separator character to the start of the new data - then, as explained in the Help file, it will replace the existing content in the combo: M23 Hi Melba23, I may be wrong but I think I'm already using the intended separator here when I populate my combo : $N1 &= "|" & $array_N1[$i] And, as said, in the help file : Quote If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed Thats's why i'm destroying the previous list here : GUICtrlSetData($ComboCatN1,"") ;Reset Combo But it does not work as intended : the combobox does not keep the entire previous list but adds the previous selected item at the beginning of the new list. I join pictures to explain it clearly. Link to comment Share on other sites More sharing options...
Nine Posted January 24, 2021 Share Posted January 24, 2021 It would be much more effective if you were to provide something runable for us. By giving us images and parts of a script, we need to guess what is your issue. For now on, please post a fully executable script with the effective way to replicate your problem. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Slhama Posted January 24, 2021 Author Share Posted January 24, 2021 35 minutes ago, Nine said: It would be much more effective if you were to provide something runable for us. By giving us images and parts of a script, we need to guess what is your issue. For now on, please post a fully executable script with the effective way to replicate your problem. You're right Nine. Here's a fully functional part of my code with which I can reproduce the problem (I just removed the non-essential parts & still have the same behavior) : expandcollapse popup#include <Array.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <Constants.au3> #include <EditConstants.au3> #include <File.au3> #include <FileConstants.au3> #include <GDIPlus.au3> #include <GuiComboBox.au3> #include <GuiConstants.au3> #include <GUIConstantsEx.au3> #include <INet.au3> #Include <Misc.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <StringConstants.au3> #Include <WinAPI.au3> #include <WinAPIEx.au3> #include <WinAPIFiles.au3> #include <WindowsConstants.au3> Global $N1 = "" Global $Srv = "" Global $NbrGrp = DirGetSize(@ScriptDir,3)-1 $Grps = _FileListToArray(@ScriptDir,"*.ini",1) If $NbrGrp[1] = 1 Then GUICtrlSetData($ComboService, $Grps, $Grps) EndIf For $i = 1 to UBound($Grps)-1 $Srv &= "|" & $Grps[$i] Next #Region ### START Koda GUI section ### $FormDemandeIT = GUICreate("Demande IT", 507, 685, 481, 127, $WS_OVERLAPPEDWINDOW) GUISetBkColor(0xFFFFFF) GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES') GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetColor(-1, 0xFFFFFF) $ButtonSend = GUICtrlCreateButton("Envoyer", 8, 620, 489, 57) $LabelService = GUICtrlCreateLabel("Service *", 8, 102, 60, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $ComboService = GUICtrlCreateCombo("", 8, 118, 489, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetData($ComboService,$Srv) $LabelCatN1 = GUICtrlCreateLabel("Catégorie *", 8, 144, 70, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $ComboCatN1 = GUICtrlCreateCombo("", 8, 160, 489, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $LabelCatN2 = GUICtrlCreateLabel("Sous-catégorie *", 8, 186, 100, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $ComboCatN2 = GUICtrlCreateCombo("", 8, 202, 489, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $LabelDescription = GUICtrlCreateLabel("Description *", 8, 230, 100, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Description = GUICtrlCreateEdit("", 8, 248, 489, 217) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Logo = GUICtrlCreatePic("C:\Windows\WinSxS\amd64_microsoft-windows-s..l-wallpaper-windows_31bf3856ad364e35_10.0.18362.1_none_ad6f96302daa2dbf\img0_1366x768.jpg", 10, 0, 268, 81) $Title = GUICtrlCreateLabel("Demande IT", 285, 8, 228, 40) GUICtrlSetFont(-1, 30, 400, 0, "Calibri") GUICtrlSetColor($Title, 0x004a98) $Group1 = GUICtrlCreateGroup("Pièces jointes", 8, 475, 489, 140) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Label6 = GUICtrlCreateLabel("Glissez-déposez vos pièces jointes ici (maximum 5)", 91, 545, 306, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func Cat_ShortCode() $N1 = GUICtrlRead($ComboCatN1) $N2 = GUICtrlRead($ComboCatN2) Global $ShortCode = IniRead($Ini, $N1, $N2, "") EndFunc Func N2() $N1 = GUICtrlRead($ComboCatN1) $array_N2 = IniReadSection($Ini, $N1) If IsArray($array_N2) Then $N2 = "" For $i = 1 To $array_N2[0][0] $N2 &= "|" & $array_N2[$i][0] Next GUICtrlSetData($ComboCatN2, $N2) EndIf EndFunc While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ComboCatN1 GUICtrlSetData($ComboCatN2,"") ;Erase Combo2 content at every combo1 selection change N2() ;Call func Case $ComboService ;Dpt choice GUICtrlSetData($ComboCatN1,"") ;Reset Combo GUICtrlSetData($ComboCatN2,"") ;Reset Combo Global $Grp = GUICtrlRead($ComboService) $Ini = @ScriptDir & "\" & $Grp ;path to ini file $array_N1 = IniReadSectionNames($Ini) ;read sections For $i = 1 To $array_N1[0] $N1 &= "|" & $array_N1[$i] Next GUICtrlSetData($ComboCatN1, $N1) ;Populate combo Case $ComboCatN2 Cat_ShortCode() ;Call func EndSwitch WEnd I join the 2 .ini files needed, they must be placed in the same folder as the script. Select "A.ini" in the first combo, you will obtain "Cat A" & "Cat AA" in the second. Select "Cat AA". Change selection in first combo to "B.ini". The second combo will have "Cat AA", "Cat B" & "Cat BB" instead of just "Cat B" & "Cat BB" as intended with the ini files. A.ini B.ini Link to comment Share on other sites More sharing options...
Slhama Posted January 25, 2021 Author Share Posted January 25, 2021 Ok guys, just forgot my problem, I just forgot to reset my var $N1 Added : $N1 = "" Works like a charm. Thanks for trying to help me 👍 (no code during weekends for me anymore) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 25, 2021 Share Posted January 25, 2021 @Slhama If you let me suggest you one thing, then you should reset the comboboxes' content everytime the user clicks on one of them, because they are filled anytime they're clicked, having the same information repeated Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
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