Click to See Complete Forum and Search --> : Autocomplete textbox or dopdown in C#
kishan.varma
October 1st, 2008, 12:28 AM
Hi
Can anybody plz provide me the sample code for Autocomplete textbox or dropdown.I want textbox or dropdown where I can type 'A' and get all words starting with 'A' then if I type 'P'then all words starting with 'AP' should be shown.
Eg:Srinivas
Srikanth
Sathish
are 3 words if I type 'S' all 3 words should be displayed,if i press 'Sr' only Srinivas & Srikanth are to be showed.
Thanx in Advance
Kishan
MNovy
October 1st, 2008, 01:36 AM
Your solution requires a list with all available items in it,
Furthermore your ComboBox items list must be generated on-the-fly.
YOu have just to check the input with the list and add those item list to the combobox:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
// list with items
string[] myList = new string[] { "Adam", "Aron", "Aaron", "Aragon", "Book", "Booker", "Brown" };
public Form1()
{
InitializeComponent();
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
comboBox1.Items.Clear();
comboBox1.SelectionStart = comboBox1.Text.Length;
//check ComboBox input
foreach (string item in myList)
{
if (item.StartsWith(comboBox1.Text)) comboBox1.Items.Add(item);
}
}
}
}
dannystommen
October 1st, 2008, 04:33 AM
Take a look at the AutoCompleteCustomSource, AutoCompleteMode and AutoCompleteSource properties of a TextBox
JonnyPoet
October 1st, 2008, 08:05 AM
What are you talking about exactly ? 'All Words' ????
You may have a selection of words in an itemlist and this words then are known of your code and it will look for it. You can built up a 'memory' which adds words automatically when they are used and store them into a list. But having 'all words' will get you application slowing down very quick and is also useless. For example german words are more then 300.000 as much as I know and all of them beginning with 'A' are hmm... approx 10.000 IMHO so if you type 'a' and a list opens showing 10000 words beginning with 'a' ??
:D So what are you really talking about?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.