Jeff schrieb:
> 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.
> 
> Any ideas? What am I doing wrong?
> 
> I am using Gambas 2.7.1 on Ubuntu Ibex
> 
> 

Presumably not much wrong - as far as I know, there's no Tag property 
for each item in a ComboBox like e. g. in a TreeView. Such a tag could 
be used to overcome this drawback of sorting-and-confusing the list.


In my projects I have been using two approaches to solve the problem:

1) Make a second array with the same contents, unsorted, and search for 
the item clicked on in the ComboBox. This will deliver proper results 
only when the items are unique. (You don't need to give an index if you 
sort it anyway.)

ComboBoxProjects.Add("ZZ")
Background.Add("ZZ")
ComboBoxProjects.Add("AA")
Background.Add("AA")

ComboBoxProjects.Sort()

...when clicked:
PRINT Background.Index(Background.Find(ComboBoxProjects.Current.Text))

(CAUTION: I didn't test this, it's written from memory...)


2) Don't sort the ComboBox list but feed it with a readily sorted and 
indexed list from you.

Hope it helps...

Rolf

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Gambas-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to