Sign in to follow this  
Followers 0
Goodkeeper

The best way to use combobox?

12 posts in this topic

Hi,

What is the correct or best way to control elements with combobox? I'm checking the state of combobox with 'while 1' and then hiding/showing the elements manually, but I know this can't be the correct way to do it as it's clumsy and breaks easily... so what is? How do you guys change the elements with combobox?

Please, answer in detail, as I'm very new to autoit.

Thanks

Share this post


Link to post
Share on other sites



Goodkeeper,

Can you explain a little more clearly what you are trying do? What exactly triggers the "hiding/showing" of the elements? :huh:

You can reset the contents of a combo with GUICtrlSetData - you just have to start the string with the separator character (default is "|"). :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

First of all I'm not sure if I should be hiding/showing guielements, but as I don't know other way...

Idea: I have two elements: combobox & inputbox

I've 3 different options in combobox: text1|text2|text3 and by selecting one of these options, the content of inputbox should change. For an eg "This is an inputbox for combo option text1" "this is for text2" and so on.. and all this should be done so that I can later in my script get the data of inputbox under combobox option "x".

Share this post


Link to post
Share on other sites

Goodkeeper,

Is this heading in the right direction? ;)

#include <GUIConstantsEx.au3>
#include <Array.au3>

Local $aList[3][2] = [["text1", "This is an inputbox for combo option text1"], _
                      ["text2", "This is an inputbox for combo option text2"], _
                      ["text3", "This is an inputbox for combo option text3"]]

$sCombo_List = ""
For $i = 0 To UBound($aList) - 1
    $sCombo_List &= "|" & $aList[$i][0]
Next

$hGUI = GUICreate("Test", 500, 500)

$cCombo = GUICtrlCreateCombo("", 10, 10, 250, 20)
GUICtrlSetData(-1, $sCombo_List)

$cInput = GUICtrlCreateInput("", 10, 100, 250, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            $sSel = GUICtrlRead($cCombo)
            $iIndex = _ArraySearch($aList, $sSel)
            If $iIndex <> -1 Then
                GUICtrlSetData($cInput, $aList[$iIndex][1])
            EndIf
    EndSwitch

WEnd

If so, then do I understand that you want to replace the combo elements in some way by entering data into the input? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Yes, your example is very near to what I mean to achieve. The only thing missing is that it doesn't save new inputbox values.

For an eg. when I select "text2" and change the input value from "This is an inputbox for combo option text2" to "hello world" it doesn't save the new value (when I come back to text2, its back to the original text)...

Share this post


Link to post
Share on other sites

Goodkeeper,

How do you want to trigger the change? A button? Pressing {ENTER} when the new text is finished? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Actually I would prefer if I shouldn't have to press anything.

When I type "hello world", change to text1 and back to 2 it would still be there.

Share this post


Link to post
Share on other sites

Goodkeeper,

That exercised the little grey cells! :D

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

Local $aList[3] = ["This is an inputbox for combo option text1", _
        "This is an inputbox for combo option text2", _
        "This is an inputbox for combo option text3"]


$hGUI = GUICreate("Test", 500, 500)

$cCombo = GUICtrlCreateCombo("", 10, 10, 250, 20)
_Fill_Combo("")

$cInput = GUICtrlCreateInput("", 10, 100, 250, 20)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            $sSel = GUICtrlRead($cCombo)
            $iIndex = _ArraySearch($aList, $sSel)
            If $iIndex <> -1 Then
                GUICtrlSetData($cInput, $aList[$iIndex])
            EndIf
    EndSwitch

WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $iCode
        Case $EN_CHANGE
            Switch $iIDFrom
                Case $cInput
                    $sSel = GUICtrlRead($cCombo)
                    $iIndex = _ArraySearch($aList, $sSel)
                    If $iIndex <> -1 Then
                        $aList[$iIndex] = GUICtrlRead($cInput)
                    EndIf
                    _Fill_Combo(GUICtrlRead($cInput))
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_COMMAND


Func _Fill_Combo($sNew_Item)
    Local $sCombo_List = ""
    For $i = 0 To UBound($aList) - 1
        $sCombo_List &= "|" & $aList[$i]
    Next
    GUICtrlSetData($cCombo, $sCombo_List, $sNew_Item)
EndFunc   ;==>_Fill_Combo

How is that? Please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

haha, didn't except this to be so complicated :D

Your code is again a bit closer to what I'm searching for, but now the actual combobox's option texts are changing too! There should be text1, text2, text3 -options and only the input box should change value :D

Think this as a tab: You have different tabs with different content. Changing element values inside tabs does not affect to other tabs' elements and so on.

Share this post


Link to post
Share on other sites

Goodkeeper,

I think I have it this time - back to a 2D array: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

Local $aList[3][2] = [["text1", "This is an inputbox for combo option text1"], _
                      ["text2", "This is an inputbox for combo option text2"], _
                      ["text3", "This is an inputbox for combo option text3"]]

$hGUI = GUICreate("Test", 500, 500)

$cCombo = GUICtrlCreateCombo("", 10, 10, 250, 20)
Local $sCombo_List = ""
For $i = 0 To UBound($aList) - 1
    $sCombo_List &= "|" & $aList[$i][0]
Next
GUICtrlSetData($cCombo, $sCombo_List)

$cInput = GUICtrlCreateInput("", 10, 100, 250, 20)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            $sSel = GUICtrlRead($cCombo)
            $iIndex = _ArraySearch($aList, $sSel)
            If $iIndex <> -1 Then
                GUICtrlSetData($cInput, $aList[$iIndex][1])
            EndIf
    EndSwitch

WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $iCode
        Case $EN_CHANGE
            Switch $iIDFrom
                Case $cInput
                    $sSel = GUICtrlRead($cCombo)
                    $iIndex = _ArraySearch($aList, $sSel)
                    If $iIndex <> -1 Then
                        $aList[$iIndex][1] = GUICtrlRead($cInput)
                    EndIf
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_COMMAND

How is that? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Yup, you nailed it. That's exactly what I was looking for.

Thanks for your help, big time.

Share this post


Link to post
Share on other sites

Goodkeeper,

Glad we got there in the end. :)

But you might want to brush up your explaining skills a bit - I was in the dark as to what you were actually after for most of this thread! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0