簡體   English   中英

通過文本框更改下一個組合框

[英]change next combobox by textbox

我通過單擊帶有以下代碼的按鈕來創建一些文本框和組合框:

/////////////////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()
    {

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM