I think I'm having a related problem.
What I want to do is populate a combobox based on a datasource but I don't want the SelectedItemChanged event to fire until after it is populated. So I have the following in the form's constructor:
comboBox1.DataSource = myDataSource; comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
where myDataSource is a DataSet or DataTable (either populated from a database or created by hand).
When I do this, though, the SelectedIndexChanged event fires a number of times (I think one per item being added but I haven't checked). When I create the list items manually instead (i.e. with comboBox1.Items.Add("firstItem"), etc.), the event doesn't fire, which is what I want.
When I put the code in the page's load event rather than the constructor, it works fine for this simple example, too. However, in the more complex real-world application I'm working on, it doesn't. In that application, the only thing that works is to populate the combobox in the constructor and set up the SelectedIndexChanged event in the page's load event.
Alack and alas. |