keyPressEvent before character is there -TextBox

19 views
Skip to first unread message

tanteanni

unread,
Jul 12, 2011, 5:47:10 AM7/12/11
to google-we...@googlegroups.com
i am trying to implement a live search with a text box. i am triggering the search on KeyPressEvent. My Problem is, that the event is fired before the text is set. so on keyPressEvent i can't get the current text from textBox. Ho to solve this? Is there an event better suited for lifesearch?

cruser

unread,
Jul 12, 2011, 5:52:33 AM7/12/11
to google-we...@googlegroups.com
Look at using the KeyUpEvent, that should work

Jens

unread,
Jul 12, 2011, 5:52:59 AM7/12/11
to google-we...@googlegroups.com
Use KeyUpEvent/Handler instead of KeyPressEvent/Handler. Also you should build in a small timer so you do not fire server requests on every KeyUpEvent. So on each KeyUpEvent you schedule the same timer instance that should execute in the next 50ms (just an example). The timer then does the server search request. That way you will always ask the server for the search result 50ms after the last key has been typed. So it reduces the amount of server requests while typing in the textbox.

tanteanni

unread,
Jul 13, 2011, 1:52:00 AM7/13/11
to google-we...@googlegroups.com
thx thats it (KeyUp  works fine). (in meantime i also tried keyDownEvent :-|)

Reply all
Reply to author
Forward
0 new messages