Using ComboBox AutoComplete
Sunday, December 31, 2006
There is has been a few posts on Windows Forms general forum on this subject.
This is my answer to getting a AutoComplete up and running.
So the first thing you need to be aware of is that your comboBox has to be
ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown
You then need to put decided on a style .. (From MSDN info)
Member name
Description
Append
Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.
None
Disables the automatic completion feature for the ComboBox and TextBox controls.
Suggest
Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.
SuggestAppend
Applies both Suggest and Append options.
ComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource
After setting these basic settings you need to loop through your datasource .. so that could be DataTable,Array, Collection of objects.
Collection of objects
If you are going to use custom source you need to set it up.
for(int f = 0; f < ent.Count; f++ )
{
ExerciseEntity ex = (ExerciseEntity)ent[f];
ComboBox1.AutoCompleteCustomSource.Add(ex.ExerciseName);
}
or DataTable
foreach(DataRow dr in DataTable1.Rows)
{
string exerciseName = dr["ExerciseName"]
ComboBox1.AutoCompleteCustomSource.Add(exerciseName);
}
You are basicly adding to a string collection. Once this is done you should be set.
You can I have also ound out set the ComboBox1.AutoCompleteCustomSource
With also a direct DataTable, but I have yet to prove this.. Happy AutoComplete.

