Strange comboBox listIndex behaviour

For questions and postings not covered by the other forums
avinashrao
Posts: 6
Joined: Tue Nov 09, 2010 1:41 pm

Strange comboBox listIndex behaviour

Postby avinashrao » Thu Mar 31, 2011 4:07 pm

Hello all,

I have a combo box which is being used to display a collection of 22 teams of class type Tm_Team with a 'name' property of type String. The displayRow method returns the team name.

However, when I iterate through the comboBox list and write the listIndex to the output viewer, the maximum listIndex value I get is 20. All 22 teams are displayed in the comboBox. When I start from the first entry and iterate to the last the sequence is as follows:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,19,20

When I iterate from the last entry to the first, the sequence is as follows:

20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,2,1

Such behaviour causes issues when using methods such as obj = comboBox.itemObject[comboBox.listIndex] where an invalid array index exception is raised.

Could anyone offer any explanation for this behaviour?

Cheers,

Avinash.

avinashrao
Posts: 6
Joined: Tue Nov 09, 2010 1:41 pm

Re: Strange comboBox listIndex behaviour

Postby avinashrao » Thu Mar 31, 2011 4:26 pm

As an addition - comboBox.listCount() returns 20 in this situation even though 22 items can be counted by visually looking at the drop-down menu in the gui.

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Strange comboBox listIndex behaviour

Postby BeeJay » Thu Mar 31, 2011 5:18 pm

Avinash,

When you use displayCollection to populate a ComboBox it only displays a "window of entries" from the underlying collection. This is so that if you 1,000s of entries, it performs fast as only 20 entries are ever loaded to the ComboBox at one time. You need to write your code so that it is aware of this "window of entries" behaviour and does the appropriate thing with respect to the entries in the ComboBox and listCount etc.

Note: If you never expect to have 1,000s of entries, you may find it easier to use listCollection instead of displayCollection, depending on your specific coding requirements.

Cheers,
BeeJay.

torrie
Posts: 92
Joined: Fri Aug 14, 2009 11:24 am

Re: Strange comboBox listIndex behaviour

Postby torrie » Thu Mar 31, 2011 7:25 pm

Hi Avo

Rather then coding

oTeam := comboBox.itemObject[ comboBox.listIndex ];

When using the displayCollection method to populate a combo box you can then just use

oTeam := comboBox.listObject.Team;

When loading the form once the combox box's displayCollection method has been called, you can also just set the listObject to select an item in the box e.g.

comboBox.listObject := player.myTeam;

If the form is a pop up edit form e.g. a new instance is displayed to edit each object, then we try to pass the selected object (Team in this case) to the displayCollection method as the start object. This way the combo box is unlikely to be loaded with 20 entries and then reloaded with another 20 entries when you set the listObject later in code e.g.

comboBox.displayCollection( root.allTeams, false, ComboBox.DisplayCollection_Prior, player.myTeam, "<None" );

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Strange comboBox listIndex behaviour

Postby BeeJay » Fri Apr 01, 2011 7:45 am

If the form is a pop up edit form e.g. a new instance is displayed to edit each object, then we try to pass the selected object (Team in this case) to the displayCollection method as the start object. This way the combo box is unlikely to be loaded with 20 entries and then reloaded with another 20 entries when you set the listObject later in code
There's a more important reason to utilise the startObject parameter. If the object isn't in the "window of objects" currently loaded by displayCollection, then findObject won't actually find it.

Cheers,
BeeJay.

avinashrao
Posts: 6
Joined: Tue Nov 09, 2010 1:41 pm

Re: Strange comboBox listIndex behaviour

Postby avinashrao » Fri Apr 01, 2011 9:04 am

Thanks Beejay and Torrie,

That was very helpful! Will alter the code as you said - using the start object is the perfect solution in the context I have. Guess the beginners Jade course doesn't teach you everything!

Cheers guys,

Avinash.


Return to “General Discussion”

Who is online

Users browsing this forum: Google [Bot] and 20 guests