Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to clear a combobox?
Message
De
29/04/2004 10:05:28
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00898211
Message ID:
00899323
Vues:
25
Do you have a SelectedIndexChanged or SelectedValueChanged EventHandler? These events fire many times when a control is first instantiated. Typically what I do is to not DataBind and not set up the delegates for the eventhandlers until the Form load instead of in the Form's init. (This means having to do it manually in code instead of in the Property Sheet).

~~Bonnie


>I have a WinForm where the user can select criteria for a database search. On the form (among other controls) is a combobox which is bound to a table in a dataset. When the form appears, I want the combobox display item to be empty. So I created a method ClearAll() that sets
>
>this.MyComboBox.SelectedIndex = -1;
>
>I tried placing a call to this method at the end of the form Load method, after filling the dataset, but this did not work. However, I did add a command button to the form and put the call
>
>this.ClearAll();
>
>in the click event handler of the command button. This did have the desired effect of clearing the combobox display item. So apparently calling ClearAll in the Load method is too early in the sequence of events as the form becomes visible.
>
>How can I get the combobox to display empty initially? Is there a later form event that should handle this?
>
>TML
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform