all groups > dotnet windows forms databinding > october 2006 >
You're in the

dotnet windows forms databinding

group:

ComboBox - Losing binding


ComboBox - Losing binding s26f84 NO[at]SPAM gmail.com
10/24/2006 2:59:10 PM
dotnet windows forms databinding:
Hey Guys&Gals

my combo box is never empty it always have the text from the first
member of the table... Plz help


my code:

this.cbo.DataSource = SearchData.Tables["Name"];
this.cbo.ValueMember = "ID";
this.cbo.DisplayMember = "Name";
this.cbo.SelectedIndex = -1;
this.cbo.Text = " ";





Sunny
Re: ComboBox - Losing binding Bart Mermuys
10/26/2006 8:25:17 PM
Hi,

[quoted text, click to view]

Once you set a DataSource to the ComboBox, then it's backed by a
CurrencyManager which keeps track of position. A CurrencyManager can't go
to -1 when the list isn't empty, that's what causing the problem.

In NET1.1, you can still force the ComboBox to select -1 if you call
SelectedIndex = -1 twice.

In NET2.0, it can be enough to set it once if ComboBox.FormattingEnabled is
true.

Both will only work at Form_Load (not form constructor).

HTH,
Greetings


[quoted text, click to view]

AddThis Social Bookmark Button