Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to clear a combobox?
Message
From
07/05/2004 12:31:11
 
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00898211
Message ID:
00901970
Views:
25
Thomas,

You can read this post if you want, but I've been playing with this since I posted this reply and have found that all this fancy stuff in this post does not solve your problem. Read my subsequent post for more details.

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

No, I don't know. You'd have to try searching for that yourself in various online sites, or maybe someone else has a link.

I hope you're using your own sub-class of the ComboBox base class. You can tweak things quite a bit that way. I've been looking through my sub-class trying to find what I've changed that enables this to work just fine for me. I can't really post the whole class, as it does quite a bit of other stuff and the code is quite lengthy, but perhaps this might help ... try adding a BindingContextChanged EventHandler to your Combo sub-class:

In your Combo's constructor:
    this.BindingContextChanged += new EventHandler(BindingContextChangedHandler);
and then the EventHandler itself:
private void BindingContextChangedHandler(object sender, System.EventArgs e)
{
	try
	{
		Binding o = this.DataBindings[this.DataBindings.Count - 1];
		if (o.DataSource is DataTable)
		{
			int nRow = ((DataTable)o.DataSource).DefaultView.Count;
			if (nRow < 1)
			{
				this.SelectedIndex = -1;
				this.Text = "";
			}
		}
	}
	catch (Exception)
	{
	}
}
At this point, I'm not sure how much this will help, because we've tweaked our Combo sub-class so much it could be an interaction of other stuff that causes ours to work correctly. But, it sure couldn't hurt to try adding this to your own Combo sub-class. Maybe I'll take a few minutes today to mess around with this and see if I can find anything else that might help you.

~~Bonnie



>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
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

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

Click here to load this message in the networking platform