[Gambas-user] Combo box

Doriano Blengino doriano.blengino at ...1909...
Thu Mar 12 22:31:47 CET 2009


Jeff ha scritto:
> Hi All,
> First post, so forgive me newbie-ness.
>
> If I use the add method to add rows to a combo box I specify an index:
> Eg: 
> ComboBoxProjects.Add("ZZ", 0)
> ComboBoxProjects.Add("AA", 1)
>
> Then in a button click event I use the index property to get the
> selected row:
>
> PRINT ComboBoxProjects.Index
>
> This is fine until I set the sort property to true on the combo box. The
> order of the text changes but the index remains the same, so selecting
> the AA row gives me an index of 0, not 1 as expected.
>   
I think there is nothing wrong... if you set the Sort property to true, 
you expect that items are sorted while you are adding them.
So, no matter in which order/index you add them, "AA" will be 0 (the 
first), and "ZZ" will be 1 (the second).
If this breaks your logic, then you must change the logic elsewhere; for 
example, if you add filenames to a such ordered combobox, then rely on 
ComboBoxProjects.Text instead of its index. If the underlying logic is 
more complicated, then sort things before adding them to the combobox 
(and don't use the combobox sorting). Or use an ancillary array, like 
Rolf-Werner suggested.

In effect, the combobox logic should be to rely on its text (think at it 
as a "controlled" input box), not on its index. The fact it can be 
automatically ordered refers to its "text" items...

Hope this could help you,
best regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list