Jump to content

How do I change default item in combobox after user selects an item


 Share

Recommended Posts

I have a combo box and it works fine. The user selects the choice from the combobox and the program

sees what is selected just fine. But how do I make the new choice the default item in the combobox.

This way, it shows what the user selected. Help...

$cmb1=GUICtrlCreateCombo("",100,185,90,20)

GUICtrlSetdata($cmb1,"2|3|4|5|6|7","2")

GUICtrlSetStyle($cmb1,0x0001,0x0800)

GUISetstate()

GUICtrlSetOnEvent($cmb1, "Combo1Change")

...

Func Combo1Change()

$text=GUICtrlRead($cmb1)

msgBox(64,"combo1","Field Count for file1=" & $text) ;this always shows what the user selected (4)

;GUICtrlSetData($cmb1," ","4") ;this does not set the default to reflect what the user selected

;GUICtrlSetData($cmb1,"2|3|4|5|6|7","4") ;this does not either

EndFunc

Any ideas??

Link to comment
Share on other sites

You could gather the ComboBox data from a txt or ini file, either before building it or by using SetData after reading the file into a variable or array... then update the file in your combo's Combo1Change() function.

You would need to do something like that anyway, if you wanted to maintain user-specific settings after closing the program.

If you're not trying to maintain settings between program executions, you could still use a variable or array to build the Combo, and update the variable when the user selects an item.

If you want to keep the first user-selection and not keep updating the default every time a new item is selected, you could set a flag variable on the first run of Combo1Change().

Hope that helps...

Link to comment
Share on other sites

I do not want to save settings. All I want to do is show 4 if they selected 4 in the combobox.

My current code ALWAYS shows the original default ("2"), no matter what they selected. But my code

does show what they selected and I just want to show that as the new default/selectedvalue in the combobox.

It seems conceptually simple but I cannot make it work. I have just tried _GUICTRLComboBoxEX_SetCurSel

and that did nothing. Any code examples you have that will do what I want is appreciated.

Joe

You could gather the ComboBox data from a txt or ini file, either before building it or by using SetData after reading the file into a variable or array... then update the file in your combo's Combo1Change() function.

You would need to do something like that anyway, if you wanted to maintain user-specific settings after closing the program.

If you're not trying to maintain settings between program executions, you could still use a variable or array to build the Combo, and update the variable when the user selects an item.

If you want to keep the first user-selection and not keep updating the default every time a new item is selected, you could set a flag variable on the first run of Combo1Change().

Hope that helps...

Link to comment
Share on other sites

Ok, I think I understand... you're not really trying to change the *default* value displayed, but you'd like the *selected* value to display, as one would expect in a control of this type.

I looked more closely at your code and tested it, and the only way I could make the selected value show up was to remove the extra formating...

GUICtrlSetStyle($cmb1,0x0001,0x0800)

I can't really tell what style and ext. style you're applying, but at least one of them appears to be affecting the functionality of the control. Just for testing, comment that line out run it again... you'll see that the displayed value changes as it should.

Link to comment
Share on other sites

I love AutoIt - fairly similar to VB.NET but easier on many levels. I just started coding in it 2 days ago and already have a GUI up with buttons, file dialogs, input areas, labels, combo boxes etc

Joe

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