按文本框更改下一个组合框
本文关键字:下一个 组合 文本 | 更新日期: 2023-09-27 18:32:44
我通过单击带有以下代码的按钮来创建一些文本框和组合框:
/////////////////add tbxcode
TextBox textbox = new TextBox();
textbox.Location = new System.Drawing.Point(448, (35 * count) + 2);
textbox.Size = new System.Drawing.Size(100, 17);
textbox.Name = "tbxcode_" + (count + 1);
panel1.Controls.Add(textbox);
/////////////////add cbxname
ComboBox combobox = new ComboBox();
combobox.Location = new System.Drawing.Point(303, (35 * count) + 2);
combobox.Size = new System.Drawing.Size(140, 17);
combobox.Name = "cbxname_" + (count + 1);
combobox.DropDownStyle = ComboBoxStyle.DropDownList;
DataSet ds = new DataSet();
OleDbDataAdapter adp = new OleDbDataAdapter();
adp.SelectCommand = new OleDbCommand();
adp.SelectCommand.Connection = oleDbConnection1;
adp.SelectCommand.CommandText = "select * from kala";
adp.Fill(ds);
combobox.DataSource = ds.Tables[0];
combobox.DisplayMember = "name";
combobox.ValueMember = "code";
panel1.Controls.Add(combobox);
通过更改文本框值,我想更改下一个组合框选定项!我该怎么做?
首先将 OnTextChanged 事件添加到文本框中
//this when you are adding the textbox
textbox.TextChanged += TextBox_TextChanged;
private void TextBox_TextChanged(object sender, EventArgs e)
{
comboBox.Text = "Wanted Value";
}
编辑:
您应该在 CreateChildControls 方法中创建这两个控件,并使它们可见 false。单击按钮时,您应该会看到控件。我假设您在单击按钮时创建了两个控件,这是错误的。您也可以在面板中添加它们,只需使它们可见false
然后单击 使可见true
.
protected override void CreateChildControls()
{
}