Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

How set ComboBox to auto-complete?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ronald S. Cook - 28 Feb 2008 17:50 GMT
In my Windows forms app, I want my ComboBoxes to let the user begin to type
values and it start to populate (if a match is found).  But, I don't want
the user to enter a value that is not in the list.

What properties do I need to set to what to make this happen, please?

I think it the involved properties are:

DropDownStyle
AutoCompleteMode
AutoCompleteSource

... but there are lots of different settings.

thanks
zacks@construction-imaging.com - 28 Feb 2008 18:43 GMT
> In my Windows forms app, I want my ComboBoxes to let the user begin to type
> values and it start to populate (if a match is found).  But, I don't want
[quoted text clipped - 11 lines]
>
> thanks

DropDownStyle = DropDownList
Ronald S. Cook - 28 Feb 2008 19:40 GMT
That does only the first letter.

On Feb 28, 12:50 pm, "Ronald S. Cook" <rc...@westinis.com> wrote:
> In my Windows forms app, I want my ComboBoxes to let the user begin to
> type
[quoted text clipped - 12 lines]
>
> thanks

DropDownStyle = DropDownList
zacks@construction-imaging.com - 28 Feb 2008 20:21 GMT
> That does only the first letter.

Correct. As far as I am aware, that's all .NET ComboBox does for you.
If you want true autocomplete, then you are going to have to write
some custom code in the controls TextChanged event. But I wouldn't re-
invent the wheel, do a Google search, I'm sure you will fine some code
out there that does it. I personally have never looked for a .NET
version, but we use a VB6 version where I work.

> <za...@construction-imaging.com> wrote in message
>
[quoted text clipped - 19 lines]
>
> DropDownStyle = DropDownList
RobinS - 06 Mar 2008 04:49 GMT
Here's an example. This loads a list of fonts and set up autocomplete for
them. I think one of my primary sources for figuring this out was Brian
Noyes's data binding book.

//This indicates that the combobox for the font families is being loaded.
//   This is checked by the selectedIndexChanged event, which is fired
//    (I think for each entry) when the databinding is added.
private bool m_Loading = false;
private DataTable dtFonts;  //table of fonts
//collection to use for auto-completion of the font names
private AutoCompleteStringCollection m_Fonts;

private void LoadFontComboBox()
{
   //This has to be set to true when it does the databinding, or it mucks
up
   //   the fontName property of the class.
   m_Loading = true;
   //Set up datatable to bind to the combobox so you can use autocomplete.
   dtFonts = new DataTable();
   dtFonts.Columns.Add(new DataColumn("fontName"));
   m_Fonts = new AutoCompleteStringCollection();
   InstalledFontCollection m_allFonts = new InstalledFontCollection();
   foreach (FontFamily oneFamily in m_allFonts.Families)
   {
       if (oneFamily.IsStyleAvailable(FontStyle.Regular))
       {
           dtFonts.Rows.Add(oneFamily.Name);
           m_Fonts.Add(oneFamily.Name);
       }
   }
   FontFamilyComboBox.AutoCompleteCustomSource = m_Fonts;
   FontFamilyComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
   FontFamilyComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
   //databind the combobox
   FontFamilyComboBox.DataSource = dtFonts;
   FontFamilyComboBox.DisplayMember = "fontName";
   FontFamilyComboBox.ValueMember = "fontName";

   m_Loading = false;
}

RobinS.
GoldMail, Inc.
--------------------
> In my Windows forms app, I want my ComboBoxes to let the user begin to
> type values and it start to populate (if a match is found).  But, I don't
[quoted text clipped - 11 lines]
>
> thanks

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.