开发者

how to set flex combobox cursor position

I have a combobox implementation as follows - Based on user input (min 2 chars) in the editable combobox, the data provider is refreshed and drop-down opened, showing different data sets as user input varies.

Problem is that after drop-down opens, the cursor moves back to the beginning. So for instance, the user types in "ab", and wants to type in "c" to form the search string "abc". Due to the cursor re-setting its position to 0, the search string instead ends up as "cab".

Here's what I tried already (doesn开发者_如何转开发't work) : textInput.mx_internal::getTextField().setSelection(index, index);

where index = length of user input. This selects text from index to index (which effectively un-selects text) and is supposed to place the cursor at the end.

Any thoughts?


You're doing the right thing. You just have to make sure that the TextInput has focus before you set the selection index.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


    <mx:VBox>

        <mx:TextInput id="input" />

        <mx:Button label="set cursor" click="setCursor()" />

    </mx:VBox>

    <mx:Script>
        <![CDATA[

            public function setCursor ():void {
                var index:Number = input.text.length;
                input.setFocus();
                input.mx_internal::getTextField().setSelection(index, index);
            }

        ]]>
    </mx:Script>

</mx:Application>


And if you have since moved to Spark (flex 4)

input.selectRange(index, index);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜