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

佐手、 提交于 2020-01-06 08:33:10

问题


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)


回答1:


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">



回答2:


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).



来源:https://stackoverflow.com/questions/2738447/how-do-i-make-sure-that-there-is-always-something-selected-in-a-spark-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!