Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to clear a combobox?
Message
 
To
29/04/2004 10:05:28
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00898211
Message ID:
00901954
Views:
32
Bonnie,

Yes, I have a SelectedIndexChanged event handler for the combobox. If the index is not -1, the method sets the values of some other controls on the form according to the selected value in the combobox. There is no SelectedValueChanged event handler.

I tried postponing the databinding of the combobox to the form Load method as you suggested, but this didn't work. Something is occurring after form Load that is changing MyComboBox.SelectedIndex.

Do you know where I can find a description of the sequence of events that fire when a Windows form is instantiated and shown?

I am not having any problem clearing other comboboxes on the form where I add values to the Items collection rather than binding to a dataset.

---TML

>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
Thomas M. Lamm
Bradbury & Associates
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform