Jump to content

GUI Update after IniDelete


Go to solution Solved by Melba23,

Recommended Posts

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

  • Moderators

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): ;)

#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
WEnd
All clear? :)

M23

Edited by Melba23
Added "Delete" code

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

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 by Seminko
Link to comment
Share on other sites

  • Moderators
  • Solution

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

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

  • Moderators

Seminko,

Glad I could help. :)

M23

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