C# Tutorial

adplus-dvertising
Autocomplete Text in ComboBox Using C#
Previous Home Next

We can also create AutoCompleteStringCollection programmatically. The following code creates an AutoCompleteStringCollection, adds strings to the collection, and sets it to the AutoCompleteCustomSource of the ComboBox

Code For AutoComplete Text in ComboBox Using C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class combobox : Form
{
public combobox()
{
InitializeComponent();
}
private void combobox_Load(object sender, EventArgs e)
{
AutoCompleteStringCollection data = new 
	AutoCompleteStringCollection();
 data.Add("Mohit");
 data.Add("Mukandlal");
 data.Add("Mukesh");
 data.Add("Manju");
 data.Add("Alok");
 data.Add("Amit");
 data.Add("Ashish");
comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox1.AutoCompleteCustomSource = data;
}
}
}

output

Previous Home Next