Solved

Limit Combobox selection to items

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Clone Visual studio 2013 solution 5 24
Form design in vb.net 7 34
VB.NET HttpWebRequest 12 55
Allow user to hide and show datagridview columns 4 17
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 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

12 Experts available now in Live!

Get 1:1 Help Now