2012-12-09 2 views
1

© 뭔가에 대한 계산이있어서 동적으로 이렇게 형식을 생성하십시오.이벤트 바인딩하기 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 항목을 변경하면 텍스트 상자가 변경 될 수 있습니다. 나는 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

답장을 보내 주셔서 감사합니다. couldnt는 내가 그것을 미안하게하고 싶은 것을 말할 수 없다. 나는 폼의 모든 컨트롤을 찾고 특정 컨트롤 아이템을 찾는 것에 대한 나의 문제를 해결한다. 다시 한번 감사드립니다. – Acablack