繁体   English   中英

如何绑定事件comboBox -TextBox

[英]How to Bind Event comboBox -TextBox

İ对某事进行计算,并以此动态创建表单。

 comboboxAdet.Size = new System.Drawing.Size(100, 300);
            comboboxAdet.Location = new System.Drawing.Point(515, 5);
            comboboxAdet.Margin = new Padding(2, 3, 2, 3);
            comboboxAdet.SelectedIndexChanged += new EventHandler(combobox_SelectedindexChanged);
            /**************************************************/
            TextBox textSatirtoplam = new TextBox();
            textSatirtoplam.Text = satirhesapla(i);
            textSatirtoplam.Name = "labelSatirToplam" + i.ToString();
            textSatirtoplam.Size = new System.Drawing.Size(100, 300);
            textSatirtoplam.Location = new System.Drawing.Point(630, 5);
            textSatirtoplam.MouseClick += new MouseEventHandler(combobox_SelectedindexChanged);
            textSatirtoplam.Visible = true;

问题是当我更改comboxBoxSelected项时,文本框可以更改。 我尝试了事件处理程序,但失败了。 那意味着如何到达文本框?

在此处输入图片说明

如果您帮助我,我会很高兴! 谢谢,我希望这很清楚。

如果我正确理解了您的问题,则希望更新与发生SelectIndexChanged事件的行相同的文本框。

您可以使用委托并将闭包传递给事件以获取对文本框的引用。

var combox = new ComboBox();
// code left out

var txtBox = new TextBox();
// code left out

combox.SelectedIndexChanged += delegate(Object sender, EventArgs e)
{
    var destTextBox = txtBox;  // important assign closure to a local variable.
    var srcCombo = (ComboBox) sender;

    destTextBox.Text = srcCombo.SelectedText;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM