VB .NET:  Programmatically set ComboBox selection

Posted on 2003-03-25
Medium Priority
Last Modified: 2012-05-04
Suppose I have a combobox control in VB .NET that is assigned to a DataSource:

'ae.fnReturnAEList.Tables(0) returns a DataSet object
ComboBoxAELookup.DataSource = ae.fnReturnAEList.Tables(0)

Then the end-user types something in the ComboBox that is not in the list.

Since the value typed in is not in the list, an error results.

What I would like to do is default to the first item in the ComboBox (whatever that might be).


Question by:Tom Knowlton
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

Author Comment

by:Tom Knowlton
ID: 8206698
>>What I would like to do is default to the first item in the ComboBox (whatever that might be).

This would happen when the Focus leaves the ComboBox.

Accepted Solution

reaves earned 200 total points
ID: 8206813
Can you change the DropDownStyleProperty to "DropDownList"? That will prevent anything from being entered that is not on the list.

You can also choose the first item as the default by setting the SelectedIndex property to 0.

Author Comment

by:Tom Knowlton
ID: 8206838
I am not sure if the business rules allow me to set the style to "DropDownList".  I'll check on that.

For now I went with you second suggestion.

I actually found this on my own while waiting for a resonse, but it will be nice to have this question captured for future reference.



Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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