Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello,

I have a windows application build up using C#. I want to open autocomplete suggestions as soon as textbox gets focus.
I don't want to use any custom control. I want to use windows.form textbox control with properties like AutoCompleteMode and so on, and want to explicitly mention this behavior.

Set autocomplete properties for textbox and as soon as you start typing it opens the list for autocomplete. But my requirement is as soon as textbox gets focus it should open the autocomplete list.

Hope I have clarified my requirements.


Thank you,
Nishant
Posted
Updated 17-Apr-11 20:36pm
v2
Comments
Sergey Alexandrovich Kryukov 15-Apr-11 13:48pm    
What's wrong with AutoCompleteMode property and the sample you can find on the documentation page referenced by Prerak? What are you missing?
--SA

Answering follow-up question:
But my requirement is as soon as textbox gets focus it should open the autocomplete list. Hope I have clarified my requirements.
This is not how auto-complete works. If you need to show all list, use System.Windows.Forms.ComboBox — it can do exactly what you want (you may want to handle GotFocus).

As to auto-complete, it is not supposed to show a list before you type anything, it would defeat the purpose of the auto-complete. The list depends on what the user types, and the list can change on every character typed.

(You may want to simulate typing using System.Windows.Forms.SendKeys but I strongly recommend avoiding it. For a record: in your GotFocus even handler you could artificially go to the end of edit buffer and simulate typing a blank space followed by backspace; it would show the list as if the user just typed characters already in buffer, but… do yourself a favor: don't touch already good auto-complete functionality! Your requirement is simply wrong; don't spoil good thing.)

—SA
 
Share this answer
 
Comments
Espen Harlinn 18-Apr-11 17:51pm    
Good points, my 5
Sergey Alexandrovich Kryukov 18-Apr-11 22:21pm    
Thank you, Espen.
--SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Apr-11 13:47pm    
My 5, but I don't understand what OP is missing, he must be familiar with that property already.
--SA
nishantkainth 18-Apr-11 6:10am    
Hi, Thank you for your answers. The link you posted has an example where you set autocomplete for textbox and as soon as you start typing it opens the list for autocomplete. But my requirement is as soon as textbox gets focus it should open the autocomplete list. Hope I have clarified my requirements. Thank You
Prerak Patel 18-Apr-11 7:23am    
You may like to check this
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/fa1d73fc-bdee-48d8-9abd-a28591c307cf
Sergey Alexandrovich Kryukov 18-Apr-11 12:41pm    
Prerak, I've posted my Answer to explain the user what can be done and why it is not recommended, please see.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900