Combobox default problem

C

chris in grimsby

I have a combobox of dropdownlist style as one of the controls on a
tabbed form.

The list is populated by setting the DataSource property to a dataset
and then the DisplayMember and ValueMember properties are set to the
names of 2 of the fields in the dataset.

I noticed that when the form displays, the combobox defaults to the
first item in the list, not to blank (selectedindex=-1) as I would
have expected. I can use the Form_Activated event to set the
selectedindex=-1 and that is ok, until a different tab is selected
followed by this tab. Now the selectedindex=0 again and the combobox
shows the first item in the list again, even though the index change
event didnt fire.
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (chris in grimsby) scripsit:
The list is populated by setting the DataSource property to a dataset
and then the DisplayMember and ValueMember properties are set to the
names of 2 of the fields in the dataset.

I noticed that when the form displays, the combobox defaults to the
first item in the list, not to blank (selectedindex=-1) as I would
have expected. I can use the Form_Activated event to set the
selectedindex=-1 and that is ok, until a different tab is selected
followed by this tab. Now the selectedindex=0 again and the combobox
shows the first item in the list again, even though the index change
event didnt fire.

BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?id=327244>
 
E

Edward Forgacs

I have also experienced this issue with MDI child forms. The fix is the same
as for tab controls:
give the combobox a different binding context to the form (which is the
default). e.g.

comboBox1.BindingContext = New BindingContext()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top