0

I have a . I provide arraylist as its data provider. my question is why moves to the ing location in when I select any item using enter key. Also when I press space from keyboard, again moves to ing location. How can I fix this? Thanks

protected function onInputKeyDown(e:KeyboardEvent):void
    {
      if(e.keyCode == 13)
      {
        AddPath(cb.textInput.text);
        cb.dataProvider = recentList;        
      }     
    }

here recentList is a Bindable ArrayList. Every Time when I enter anything in ComboBox and press Enter, The cursor moves to the beginning in the Text Area of ComboBox. AddPath function simply adds the new data to the recentList.

zero323
  • 322,348
  • 103
  • 959
  • 935
Sarfraz Ahmed
  • 1,349
  • 6
  • 23
  • 43

1 Answers1

0

When you set cb.dataProvider = recentList; you are essentially assigning a new pointer which overrides the previous list and resets the cursor.

You should be able to create a variable containing the selected item and manually set the ComboBox to that item on click/enter after you carry out the cb.dataProvider = recentList;

protected function onInputKeyDown(e:KeyboardEvent):void
{
    if(e.keyCode == 13)
    {
        var selectedItem:String = cb.selectedItem
        AddPath(cb.textInput.text);
        cb.dataProvider = recentList;   
        cb.selectedItem(selectedItem); 
    }     
}

Apologies if the code isn't perfect, but the theory should be right.

  • I tried this. but it did not work. when I change the Selection using the Arrow keys and then Press backspace. Cursor moves to the beginning. – Sarfraz Ahmed Aug 28 '12 at 09:46
  • I also add 'cb.textInput.selectRange(cb.textInput.text.length, cb.textInput.text.length);' after giving recentList as dataprovider to the combobox. it shows the cursor on right, but as soon as I press backspace, cursor moves to the beginning. – Sarfraz Ahmed Aug 28 '12 at 12:39
  • the keycode is set to 13 - try putting the var selectedItem:String = cb.selectedItem before the if statement and the cb.selectedItem(selectedItem); after the if statement – Keiran Russell Aug 28 '12 at 13:05
  • This does not work. when we even click on combobox, dropdown list open and if we click on any item, that item get selected but cursor moves to the beginning. this is something that is in new spark combobox. – Sarfraz Ahmed Aug 29 '12 at 05:23