Solved

VB.net/2005 Text/ComboBox combination

Posted on 2006-07-12
2
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

759 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