Flex : How to pre-select an Item in DataGrid
Tagged Under : DataGrid, Flex
If you want to pre-select an item in a Datagrid when it loads for the first time, this is how you can do it. The idea is really simple, just set the selectedIndex property of the Datagrid to the index you want and then scroll the DataGrid to the selectedIndex. Took me a while to figure it out. However, turns out the you need to call validateNow() before you call the scrollToindex() on DataGrid.
Sample code posted below.
Hi
I try, but it doesn’t work.
Do you have any other ways?
If you have another one, please send me a mail, thanks so much.
@paravoice, that works for me. Can you tell me exactly if you are getting any error or what?
Maybe we have a diffrent situation.
I use a Tree , not a DataGrid .
Now I use a stupid method to expend the tree until the item which I want to select is visible , then select the item.
My english is not good, so I hope you can understand.
OK, I havent tried this on Tree control but theoretically, it should work the same. I will try to put together an example today if I get some time.
@paravoice, do you have a code snippet you can show so I can see what you are trying and why its not working.
Sorry, last week I was on vocation.
It’s the most important festival in China.
Here is a code snippet, the node that the label property’s value is ‘Product Management’ should be selected, but it’s not true.
Thank you for your help.
Oh, it seems the code cannot be pasted.
I have sent the code to you by mail.
The call of “validateNow” before executing “scrollToIndex” is only needed if dataProvider of the List derived component was dynamically changed at the run-time
It doesn’t seem to work for me neither. When I run this, none of the rows are selected. Could you maybe take a look at my code?