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