У меня возникли трудности с установкой значения для нескольких текстовых полей во время события _SelectedValueChanged()
ComboBox
.
Моя форма имеет одно ComboBox
и четыре других TextBox
поля под ней. По сути, я хочу обновить значение текстовых полей при изменении ComboBox.SelectedText
.
Пока мой код выглядит так:
Особенности:
this.cmbTopic.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.hCAliasDataSet, "Items.Topic", true));
this.cmbTopic.DataSource = this.hCAliasDataSet;
this.cmbTopic.DisplayMember = "Items.Topic";
this.cmbTopic.Location = new System.Drawing.Point(81, 14);
this.cmbTopic.Name = "cmbTopic";
this.cmbTopic.Size = new System.Drawing.Size(199, 21);
this.cmbTopic.TabIndex = 0;
this.ToolTip1.SetToolTip(this.cmbTopic, "Add a new Topic");
this.cmbTopic.ValueMember = "Items.Topic";
this.cmbTopic.SelectedValueChanged += new System.EventHandler(this.cmbTopic_SelectedValueChanged);
Событие:
private void cmbTopic_SelectedValueChanged(object sender, EventArgs e)
{
string sQuery;
sQuery = "Topic = '" + cmbTopic.SelectedText + "'";
// Set the textboxes according to selected Topic value
DataRow[] dr = hCAliasDataSet.Tables["Topics"].Select(sQuery);
for (int i = 0; i < dr.Length; i++)
{
this.txtFields_1.Text = Convert.ToString(dr[i]["Description"]);
this.txtFields_2.Text = Convert.ToString(dr[i]["Family"]);
this.txtFields_3.Text = Convert.ToString(dr[i]["Options"]);
this.txtFields_4.Text = Convert.ToString(dr[i]["Group"]);
}
}
Когда программа работает, я иду, чтобы изменить значение ComboBox
, и ничего не происходит?