Monday, March 10, 2008

Finding the right element in a combobox

This post might be usefull not only for a combobox but all other list type of controls.

You have maybe found a better solution than this yourself, but I would like to show you a simple (maybe not the best) way to find specific item in a combobox. As you maybe know or have experienced Flex does only draw what you see and hence an item you do not see in the combobox is not possible to select. Due to this you will have to scroll the elements to make it visible.

I played around a couple of minutes and just created this while loop that scrolls all the items, and picks out the item with the itemrenderer "12"


@ie.combo_box("cbTest").open
num_rows = @ie.combo_box("cbTest").num_rows
position = 0
while(position <= num_rows)
@ie.combo_box("cbTest").scroll(:position => position)
begin
@ie.combo_box("cbTest").select(:item_renderer => "12")
position = num_rows + 1
rescue
position += 1
end
end


Support for this might be built into the FunFX framework, that it searches like that automatically, or what do you think?