Seminko Posted June 10, 2014 Share Posted June 10, 2014 Hey fellas, I have this Combo in my GUI that displays section names in my *.ini file. The script goes like this: Global $sections = IniReadSectionNames("config.ini") $Combo1 = GUICtrlCreateCombo("", 64, 496, 169, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) for $i = 1 to UBound($sections,1) - 1 GUICtrlSetData($Combo1, $sections[$i]) Next GUICtrlSetOnEvent(-1, "Combo1Choose") Now when I want to create a section in the ini file I press a button and it creates an entry in the ini file and the combo gets updated. The button goes like this: IniWrite ( blaa bla bla) $sections = IniReadSectionNames("config.ini") for $i = 1 to UBound($sections, 1) - 1 GUICtrlSetData($Combo1, $sections[$i]) Next So as I was saying the combo gets properly updated but for some reason the selected entry (what I see in the combo when it is not rolled out) jumps to the last entry from the ini file not counting the newest which we just created. I could live with that but if we can fix it, why not. Obviously when I create an entry I want it shown in the combo. For the second issue. I also have an IniDelete button which is the same as the create function above but obviously IniDelete is used instead of IniWrite. BUT When I do that, the entry remains in the combo. The selected entry again jumps to the last one created before the one we want to delete but the Section name REMAINS in the combo drop down. When I open the ini, the section is in fact deleted but somehow remains in the drop down combo UNTIL I close the GUI and call it back. Any idea how to correct the two issues? Obliged Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 10, 2014 Moderators Share Posted June 10, 2014 (edited) Seminko,You need to clear the previous combo data before reloading it. You can do this by loading just the separator character (as shown in the script below): expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $sIni = "config.ini" Global $iIndex = 1 Global $aSections = IniReadSectionNames($sIni) $hGUI = GUICreate("Test", 500, 500) $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) If IsArray($aSections) Then For $i = 1 To $aSections[0] GUICtrlSetData($cCombo, $aSections[$i]) Next EndIf $cAdd = GUICtrlCreateButton("Add", 10, 50, 80, 30) $cDel = GUICtrlCreateButton("Delete", 10, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cAdd IniWrite($sIni, "Section " & $iIndex, "1" , $iIndex) $iIndex += 1 $aSections = IniReadSectionNames($sIni) GUICtrlSetData($cCombo, "|") ; Clear current combo list <<<<<<<<<<<<<<<<< For $i = 1 To $aSections[0] GUICtrlSetData($cCombo, $aSections[$i]) Next Case $cDel IniDelete($sIni, GUICtrlRead($cCombo)) $aSections = IniReadSectionNames($sIni) GUICtrlSetData($cCombo, "|") ; Clear current combo list <<<<<<<<<<<<<<<<< For $i = 1 To $aSections[0] GUICtrlSetData($cCombo, $aSections[$i]) Next EndSwitch WEndAll clear? M23 Edited June 10, 2014 by Melba23 Added "Delete" code 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...
Seminko Posted June 10, 2014 Author Share Posted June 10, 2014 (edited) Hey Melba, delete works fine now. But when I added the reset bit to the create button, it refreshes the list but does not end on the latest entry. The field is just blank. Which is OK for the Delete button but when I press create I want the combo box to show the latest entry I created. Thx EDIT: may it have sth to do with the fact that I use Unbound in the script? for $i = 1 to UBound($sections, 1) - 1 GUICtrlSetData($Combo1, $sections[$i]) Next Where yours is just: For $i = 1 To $aSections[0] GUICtrlSetData($cCombo, $aSections[$i]) Next Edited June 10, 2014 by Seminko Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted June 10, 2014 Moderators Solution Share Posted June 10, 2014 Seminko,Then you need to create a delimited string to load the combo and add the newly created section name as the default: Case $cAdd ; Get new section name $sSection = "Section " & $iIndex ; Write to ini IniWrite($sIni, $sSection, "1" , $iIndex) ; Just for this example $iIndex += 1 ; Re-read the ini $aSections = IniReadSectionNames($sIni) ; Create a string to hold the data $sData = "" ; Loop through the returned array For $i = 1 To $aSections[0] ; Add each string with a delimiter - note we begin with a delimiter to overwrite the current data $sData &= "|" & $aSections[$i] Next ; Now load the combo and set the new section name as default GUICtrlSetData($cCombo, $sData, $sSection)Better? M23 Seminko 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 Link to comment Share on other sites More sharing options...
Seminko Posted June 10, 2014 Author Share Posted June 10, 2014 Aaaah, the 'default' parameter of GUICtrlSetData. Nice Thank you! You sir, are awesome! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 10, 2014 Moderators Share Posted June 10, 2014 Seminko,Glad I could help. 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...
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