• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

VB .NET: Programmatically set ComboBox selection

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).

Thanks,

Tom
0
Tom Knowlton
Asked:
Tom Knowlton
  • 2
1 Solution
 
Tom KnowltonWeb developerAuthor Commented:
>>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.
0
 
reavesCommented:
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.
0
 
Tom KnowltonWeb developerAuthor Commented:
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.

Thanks,

Tom
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now