PDA

View Full Version : Automatically select first listItems? [Flex]



ff45t1z
September 9th, 2007, 12:41 PM
Hey all, hopefully this isn't too obvious a question, but I've been wondering...
In Flex I've built a DataGrid, inside which is contained a few options. You select an item, and several fields in the application display associated information. ( The application in question is a discography for a band. ),
However, there are buttons in the application that i've designed to link off to HTML pages containing lyrics/artwork. This works successfully, however... the buttons run on {datagrid.SelectedItem....} etc. Thus, if the user clicks the button before an item is selected Flash generates an IOerror. ( not that the user in all cases can see this. ) ( the grid loads the URL for the associated lyrics/art from XML. )
Is there a way to set Flex to automatically select the first list item?

buginajar
September 10th, 2007, 01:24 AM
Is datagrid.SelectedItem read-only? If not, couldn't you just set the value to 0 or whatever the first value is?

I have no clue how different Flex is from as3, but logically there are a couple of workarounds.

1. Initialize the button to be disabled. If there is no event being broadcast when someone selects an item on the datagrid, you could dispatch a custom event. The listener would then enable the button if it isn't already enabled;

2. Put some logic on the button click handler function that uses a default value if no item is selected.

Again, I have no idea how closely related flash and flex are, but either of these two options should fix the problem, no?