2012-12-09 33 views
1

©有一個關於某事的計算,並創建一個形式dynamiclly這樣。如何綁定事件組合框-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項目,文本框可以改變。我嘗試過eventhandler但失敗。這意味着如何到達文本框?

enter image description here

,如果你幫我,我會很開心!謝謝 我希望很清楚。

回答

0

如果我正確理解您的問題,您希望更新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; 
}; 
+0

感謝您的回覆。我無法告訴我想要什麼抱歉,我解決了我的問題,找到表單中的所有控件並找到特定的控件。再次感謝。 – Acablack