Lost in .NET Code

Developing software in .NET, Security and other ramblings.

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.

0 Comments:

Post a Comment

<< Home


Subscribe in a reader


Blogs I read

Tristan Phillips
Sarah Blow (.Net Mobile)
Mike Taulty (MS DPE)
Ian Griffths (WPF)
Jack Greenfield


Useful Links

Fircroft Trust Ltd
Unwind Software Ltd


Archives

December 2006   January 2007   February 2007   March 2007   April 2007   May 2007   June 2007   October 2007   November 2007   February 2008   April 2008   May 2008   June 2008   July 2008   August 2008  


Fun and Games



 

This page is powered by Blogger. Isn't yours?