Click here to Skip to main content
12,400,556 members (58,031 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
I have a textbox and a database.Everytime the user types something in the textbox,data with string matching textbox's string is loaded from the database.

Now,how can i show this data in the AutoComplete Mode as it appears in Search Engines?

The database i'm using is SQL.
Posted 27-Dec-12 0:29am
Updated 27-Dec-12 0:35am
v3
Comments
Asa code 11-Feb-14 23:10pm
   
also I want to know when select one item in text box and load to other column in table to another text box .... can some one help this ?
CHill60 1-Apr-14 19:53pm
   
Use the "Ask a question" link or search through CodeProject answers
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

This way...
private void Form1_Load(object sender, EventArgs e)
{
    // declare custom source.
    var source = new AutoCompleteStringCollection();
    // fetch record from database
    datatable dt = getdatafromsql("select name from tbl");
    // fill database records to custome sorurce
    for (i=0;i<dt.rows.count;i++)>
    {
         source.Add(dt.rows[i][0].tostring(););
    }
    // Create and initialize the text box.
    var textBox = new TextBox
                  {
                      AutoCompleteCustomSource = source,
                      AutoCompleteMode =
                          AutoCompleteMode.SuggestAppend,
                      AutoCompleteSource =
                          AutoCompleteSource.CustomSource,
                      Location = new Point(20, 20),
                      Width = ClientRectangle.Width - 40,
                      Visible = true
                  };
 
    // Add the text box to the form.
    Controls.Add(textBox);
}
Happy Coding!
Smile | :)
  Permalink  
Comments
Husain Sabir 27-Dec-12 7:09am
   
Got it.But i also want to scroll through the suggestions and then select a value.
Aarti Meswania 27-Dec-12 7:13am
   
okay then use an Auto complete Suggestion Combobox
visit...
http://www.codeproject.com/Articles/11899/Auto-Complete-Multi-Column-ComboBox
Husain Sabir 27-Dec-12 7:16am
   
I know that.But i don't want to use a combobox.I want to implement it in a text box.
Aarti Meswania 27-Dec-12 7:21am
   
then you have to create your own control because as i found solution on internet I have not seen this control with scroll for winform

and if want scroll then you need a button to popup suggesstion and that button at right hand side makes your textbox like combo
:)
Husain Sabir 27-Dec-12 7:31am
   
no no.ur not getting me.
i want it to be as in google search.where u get suggestions based on ur query and u can select ur relevant result from the suggestions.
Aarti Meswania 27-Dec-12 7:34am
   
I got you dear
see properly google suggestion will not show scroll!!! :)
Husain Sabir 27-Dec-12 7:40am
   
i didn't actually mean scroll.
but i just want that when i press the down key,the suggestion should be highlighted and when i press enter,the highlighted suggestion should be selected in the text box.
Aarti Meswania 27-Dec-12 7:44am
   
that will possible if done after write some char in textbox
winform auto suggestion textbox is having same behavior as google search textbox provides

so only way is using combobox
Husain Sabir 27-Dec-12 8:00am
   
ok.thank you!
Aarti Meswania 27-Dec-12 8:00am
   
Welcome! :)
Glad to help you! :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try this

public void AutoComplete() 
{
AutoCompleteStringCollection AutoItem = new AutoCompleteStringCollection();
foreach (DataRow rw in Dt.rows)
{
AutoItem.Add(Rw["columnname"].ToString());
 
}
texbox.AutoCompleteMode = AutoCompleteMode.Suggest;
texbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
texbox.AutoCompleteCustomSource = AutoItem;
}
  Permalink  
v2
Comments
Husain Sabir 27-Dec-12 6:55am
   
This works.But i also want to select from the suggestions.
Soner Gönül 27-Aug-14 8:36am
   
Then you can assing AutoCompleteMode property as well.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Sample code

textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();
getData(DataCollection); //add your database values here
textBox1.AutoCompleteCustomSource = DataCollection;


Full Source : Autocomplete Textbox

Zene
  Permalink  
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 20 Dec 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100