Solved

VB.net/2005 Text/ComboBox combination

Posted on 2006-07-12
2
236 Views
Last Modified: 2010-04-23
Hi

I wanted to know if you could use a ComboBox like a text box too.
I want my ComboBox to have have four items to choose from, but also alow the user to
type in anything else.
Is this possible?
0
Comment
Question by:murbro
2 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17089275
Yes its possible, make sure that the ComboBox's DropDownStyle property is set to DropDown (default anyway). Then you could handle the KeyPress event of the combobox like this:

Private Sub ComboBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress

        If e.KeyChar = ChrW(Keys.Enter) Then

            If Me.ComboBox1.Text <> String.Empty AndAlso Not Me.ComboBox1.Items.Contains(Me.ComboBox1.Text) Then

                Me.ComboBox1.Items.Add(Me.ComboBox1.Text)
                Me.ComboBox1.Text = String.Empty
            End If
        End If
    End Sub

---
where ComboBox1 is the name of your combobox
0
 

Author Comment

by:murbro
ID: 17089443
Thanks very much
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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