Jump to content

Update label when combobox entry selected from ini file


Recommended Posts

Hi,

So ive got a combo box that reads from an ini:

Global $ini_save_file = @ScriptDir & "\config.ini"
Global $Combo = GUICtrlCreateCombo("", 75, 15, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
_ReadComboOptions_FromINI()

and ive got a label:

$Label = GUICtrlCreateLabel("label text here", 16, 18, 50, 17)

and the ini file looks like this:

Combo_value1=1
Combo_value2=2
Combo_value3=3
Combo_value4=4
Combo_value5=5
Combo_value6=6
Combo_value7=7
Combo_value7=7a
Combo_value7=7b

Label_value1=Text1
Label_value2=Text2
Label_value3=Text3
Label_value4=Text4
Label_value5=Text5
Label_value6=Text6
Label_value7=Text7
Label_value7=Text7a
Label_value7=text7b

So what I want to happen is when I select a value in the combo box, is sets the label to the equivalant label value; EG: Combobox I select '1' and it would then automatically set Label to 'Text1' which its pulled from the ini file.

Anyone got any idea how I would do this, spent several hours trying to figure it out but got nowhere at all

Link to comment
Share on other sites

  • Moderators

quinnj09,

I have rewritten your ini file to ease the problem - note that the "keys" of the Label section must match the "values" of the Combo section:

[Combo]
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=7a
9=7b

[Label]
1=Text1
2=Text2
3=Text3
4=Text4
5=Text5
6=Text6
7=Text7
7a=Text7a
7b=text7b

Then this script works for me:

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

Global $ini_save_file = @ScriptDir & "\config.ini"
Global $aLabel_Options = IniReadSection($ini_save_file, "Label")

$hGUI = GUICreate("Test", 500, 500)
$cCombo = GUICtrlCreateCombo("", 75, 15, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
_ReadComboOptions_FromINI()
$cLabel = GUICtrlCreateLabel("", 75, 200, 145, 25)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            $sCombo_Sel = GUICtrlRead($cCombo)
            $sLabel_Text = IniRead($ini_save_file, "Label", $sCombo_Sel, "Error")
            GUICtrlSetData($cLabel, $sLabel_Text)
    EndSwitch
WEnd

Func _ReadComboOptions_FromINI()
    $aIniRead = IniReadSection($ini_save_file, "Combo")
    If Not @Error Then
        $sCombo_List = ""
        For $i = 1 To $aIniRead[0][0]
            $sCombo_List &= "|" & $aIniRead[$i][1]
        Next
        GUICtrlSetData($cCombo, $sCombo_List)
    EndIf
EndFunc

Please ask if you have any questions. :)

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