shinyhappydan
shinyhappydan

Reputation: 728

How do I make sure that there is always something selected in a Spark List?

I have a spark list, which is based on a dataProvider. As the application runs, the data in the dataprovider can change, and also the dataProvider can be swapped for a different one

What I need to do is make sure that something is always selected in the list (unless it is empty)

Upvotes: 0

Views: 373

Answers (2)

duTr
duTr

Reputation: 714

You simply have to set the property requireSelection of your list instance to true.

In MXML, it would be:

<s:List id="myList" requireSelection="true">

Upvotes: 1

falomir
falomir

Reputation: 1169

After setting its data provider ( or whenever is changed ) you could do a:

myList.selectedIndex = 0;

, so whenever the is data on your list, its first item will be selected (it could be any index, just remember that it start from 0 to length - 1).

Upvotes: 0

Related Questions