Solved

Limit Combobox selection to items

Posted on 2006-10-24
5
198 Views
Last Modified: 2008-02-01
Hi All,

In VS2005, I would like to limit the text in a combo to the items. I would like to have it to SuggestAppend, and the source is the listitems.

The style is set to DropDown and with DropDownList, you cannot use the autocomplete.

How can I achieve this?
0
Comment
Question by:nzfire
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17800163
with suggestappend you cannot enforce selection to the items, simply suggest.

set the AutoCompleteSource to ListItems, and the AutoCompleteMode to SuggestAppend for every combo or textbox you want.

was this your question?

0
 
LVL 1

Author Comment

by:nzfire
ID: 17800336
hi newyuppie,

We meet again.

I want to limit the text in the combo to the items. i.e. only allow the user to select items that are in the combo. The same way as the vb6 LimitToList.

0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17800592
one solution would be to set the DropDownStyle to DropDownList, but as you figured it out, you lose the autocomplete.

i guess there is no built-in support for this feature. maybe with a piece of code like this you can achieve that effect. put it in the combobox textchanged event:

Private Sub ComboBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TestComboBox.TextChanged

        Dim MyCombo As ComboBox = DirectCast(sender, ComboBox)

        While (MyCombo.FindString(MyCombo.Text) < 0) AndAlso (MyCombo.Text.Length > 0)
            MyCombo.Text = MyCombo.Text.Substring(0, MyCombo.Text.Length - 1)
            MyCombo.Select(MyCombo.Text.Length, 0)
        End While

    End Sub

idea from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=407416&SiteID=1
0
 
LVL 1

Author Comment

by:nzfire
ID: 17800772
Yep, thats fine.

I think that I will just stick with the simple DropDownList. there aren't many items in the combo, but I just wanted to know.

Thanks again
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17800804
yeah, there are just some of these things that where better in the old days...

thanks for the grade!

NY
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question