C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

AutoComplete Textbox in Windows Application


Posted Date: 25 Sep 2009    Resource Type: Code Snippets    Category: Visual Studio
Author: Deepika HaridasMember Level: Diamond    
Rating: 1 out of 5Points: 20



Introduction :
This code demonstrates the use of AutoComplete Textbox in Windows Application the same way as we use Ajax in Web Applications.

Pre-requisites :

Textbox properties to be set for achieving this :
1) AutoComplete Mode - You can select any from it, either Suggest/Append/SuggestAppend (In my case I have taken Suggest here)
2) AutoCompleteSource - Set it as CustomSource
3) AutoCompleteCustomSource - Its a collection
















As shown in the Figure take a form with a textbox named txtname. Here I am fetching names from the database.

public partial class Form9 : Form

{

public string strConnection = ConfigurationManager.ConnectionStrings["test1"].ConnectionString;

AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

public Form9()

{

InitializeComponent();

}

private void Form9_Load(object sender, EventArgs e)

{

OdbcDataReader dReader;

OdbcConnection conn = new
OdbcConnection();

conn.ConnectionString = strConnection;

OdbcCommand cmd = new OdbcCommand();

cmd.Connection = conn;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "Select distinct name from sample order by name";

conn.Open();

dReader = cmd.ExecuteReader();

if (dReader.HasRows == true)

{

while (dReader.Read())

namesCollection.Add(dReader["name"].ToString());

}

else

{

MessageBox.Show("Data not found");

}

dReader.Close();

txtname.AutoCompleteMode = AutoCompleteMode.Suggest;

txtname.AutoCompleteSource = AutoCompleteSource.CustomSource;

txtname.AutoCompleteCustomSource = namesCollection;

}

}




For more details, visit http://angeldeeps.blogspot.com/2009/09/autocomplete-textbox-in-windows.html



Responses

Author: Miss Meetu Choudhary    28 Sep 2009Member Level: Diamond   Points : 1
Cool Presentation, and good concept

++Thanks and Regards
Meetu Choudhary
Site coordinator


Author: Deepika Haridas    30 Sep 2009Member Level: Diamond   Points : 1
Thank you Meetu...

--
Thanks & Regards,
Deepika
Editor


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Windows Application  .  Autocomplete textbox  .  Autocomplete  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Creating report in vb.net through coding.
Previous Resource: Greeting card design for Birthday using VC++
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use