PDA

View Full Version : List Component - rowCount defaults to 7; auto size?


wGrand
06-17-2008, 08:20 PM
The <mx:List> component defaults to 7 rows.

I was able to make it readjust by initiating this code on creationComplete():

if(this.collection.length<6)
this.rowCount=this.collection.length;
else
this.rowCount=5;

But, I drag items in and out of the list and the rowCount doesn't update. Neither does its width. Is there a way to make it automatically size?

ryang
06-17-2008, 09:24 PM
Are you using mxml to call the list? Try...


<mx:List dataProvider="{collection}"
rowCount="{Math.min(collection.length, 5)}" />

wGrand
06-18-2008, 04:17 AM
Wow! Very smart. I get a warning saying that it may not be able to bind to 'collection' though

ryang
06-18-2008, 05:46 AM
make sure to make collection "bindable" where you declare it.

for example....

[Bindable] public var collection:ArrayCollection = new ArrayCollection();


if you are filling your collection from a remote object or webservice call, and your result is an Array, then make sure to set the "source" property, not the collection itself, or you will break the binding.

eg.

public function result(data:Object):void {
collection.source = data.result as Array;
}


if you are filling it manually, then use the "addItem" method to add items to your collection.

HTH,
Ryan