Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to clear a combobox?
Message
From
07/05/2004 14:08:49
 
 
To
07/05/2004 13:54:55
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00898211
Message ID:
00902008
Views:
31
Lee,

Setting the DataSource, ValueMember, etc. is setting up the stuff for populating the Combo with your codes tables or whatever you're using. Setting up the .DataBinding tells the combo which column in your data table contains the value that the Combo should display. Combo's should never be bound to SelectedText ... only to SelectedValue. That's just what I've found to work best (if your DisplayMember and ValueMember are the same, then it will probably work ok to bind to SelectedText, but if you make it a point to always bind to SelectedValue, then you won't have any possible gotcha's showing up later <g>).

Combos are different than TextBoxes in that they have two kinds of "binding" ... one to populate the combo's dropdown and one to bind to your data table.

~~Bonnie


>Bonnie,
>
> I'm just learning this .NET stuff (and probably always will be) and I was curious why you would call cboCode.DataBindings.Add(...) after setting the ValueMember property. The only reason I ask is because I've been having a lot of trouble lately with getting the SelectedValue member to reflect the value of the selected item. I do exactly as you did below, only without calling the DataBindings method. I thought setting the ValueMember property to the name of the field you wanted to bind it to would work. I've found that sometimes it does, and sometimes it doesn't. Should I be calling Databindings? And if so, why only for the SelectedValue, and not for SelectedText?
>
>-----
>Lee Perkins
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform