Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Limit Combobox selection to items

Posted on 2006-10-24
5
Medium Priority
?
203 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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