Solved

Limit Combobox selection to items

Posted on 2006-10-24
5
195 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now