Im using a set combobox (ComboBox1) to provide a selection of records from a
database table. I have a typed dataset (DataSet1) that contains the typed
datatable (DataTable1) that the combobox is bound to. The datatable in the
dataset is filled using the typed tableadapter (TableAdapter1). DataTable
consists of the typical primary key and value fields.
Here is the designer generated code for ComboBox1:
this.ComboBox1.DataSource = this.Dataset1;
this.ComboBox1.DisplayMember = "DataTable1.ValueField1";
this.ComboBox1.FormattingEnabled = true;
this.ComboBox1.Location = new System.Drawing.Point(77, 39);
this.ComboBox1.Name = "ComboBox1";
this.ComboBox1.Size = new System.Drawing.Size(303, 21);
this.ComboBox1.TabIndex = 6;
This is the forms load code:
TableAdapter1.Fill(this.Dataset1.DataTable1);
What I have problems with is that the ComboBox1, when filled in the forms
Load event code, gets it's SelectedIndex changed from -1 to 0, i.e. first
option is already selected when the form is loaded. I do not want this
behaviour and wonder what is causing it, and to me it just seems random and
unpredictable.
I have not included the rest of the forms code and settings, as I think
there is nothing out of the ordinary, I just hope someone recognizes the
condition and can explain what is causing it and how you can control it. Can
anyone shed som light on this? I understand I can just set the SelectedIndex
by code after filling the DataTable, but it's an ugly solution.
Thank you.
- Magnus