Solved

Limit Combobox selection to items

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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