How to make sure ComboBox select nothing...

  • Thread starter Thread starter Programatix
  • Start date Start date
P

Programatix

Hi,

I'm having problem with ComboBox. I'm trying to force the ComboBox select
nothing by doing this,
myCombo.SelectedText = ""
myCombo.SelectedIndex = -1
but in vain, as the ComboBox will automatically select the first available
selection.

If I make the ComboBox visible before setting the .SelectedText to "" and
the .SelectedIndex property to -1, it will be successful. But if I put the
ComboBox in a TabControl and I switch between the Tabs in the TabControl,
the ComboBox will automatically reselect the first available selection.

Anyone out there has a solution?

Thanks in advance.
 
Hello,

Programatix said:
I'm having problem with ComboBox. I'm trying to force the
ComboBox select
nothing by doing this,
myCombo.SelectedText = ""
myCombo.SelectedIndex = -1
but in vain, as the ComboBox will automatically select
the first available selection.

Try to call "myCombo.SelectedIndex = -1" twice, somethimes that helps.

Regards,
Herfried K. Wagner
 
It did, but as I have state, if I put the ComboBox into a TabControl and
switched between the Tabs in the TabControl, the ComboBox will reselect the
first available option.

I'm thinking of expanding the ComboBox by inheriting it but could not think
of a way to code it. Any idea?
 
I select the records into a dataset, then add a row with a description of
"<None>" and a value of DbNull.Value. Then I bind the combo box to that
dataset.

This lets users actually put a null in the database when appropriate. I
don't think your current efforts will achieve this.

Regards

Ron
 
Okay, here's kind of a crazy idea (but one that ought to work): Create
your own class that implements IList. In your class's constructor, take
a parameter of type IListSource; call IListSource.GetList(), and save a
reference to the IList that's returned. Then implement your class's
IList.Count property to return savedList.Count + 1, and have your
IList.Item property return "" for element 0, and otherwise return
savedList[index - 1]. Then create an instance of this class, passing
your DataTable as a parameter to the constructor; and bind your ComboBox
to this object, instead of directly to the DataTable.

Sounds like a bit of a pain, until you consider that you can then re-use
this same class for every combo box in your application...
 
Back
Top