2009-09-10 7 views
0

탭 컨트롤이있는 winform이 있습니다. 기본 탭에서 두 번째 탭 (기본값)의 텍스트 상자에서 값을 검색하는 함수에 '이동'단추가 연결되어 있습니다.C# : Window Forms : 비활성화 된 탭에서 자식 컨트롤 값 검색

처음에는 두 번째 탭에서 텍스트 상자가 기본값으로 오염 될 것으로 예상되는 경우이 값이 ""로 표시됩니다.

로드 할 때 컨트롤을 모두 채우려면 어떻게합니까?

+0

아마도 이것은 귀하의 코드와 관련이 있으며, 보지 않고도 당신을 도울 수 없습니다. –

+0

코드 : 개인 무효 개시 (개체 보낸 사람, EventArgs 전자) { 문자열 set_dateformat = combobox.date.Text; string set_nameformat = combobox.name.Text; } 두 개의 콤보 상자는 내 탭 컨트롤의 두 번째 탭에 있습니다. 이 방법은 탭 # 1의 버튼에 묶여 있습니다 –

+0

"textboxes"하지만 귀하의 코드는 "combobox" –

답변

0

이 마법처럼 작동합니다

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     ComboBox c = new ComboBox(); 
     Button b = new Button(); 

     public Form1() 
     { 
      InitializeComponent();    

      b.Text = "New Button"; 
      b.Click += new EventHandler(b_Click); 
      this.tabPage1.Controls.Add(b); 

      c.Items.Add("Hello World"); 
      c.Items.Add("My Program"); 
      c.SelectedIndex = 0; 
      this.tabPage2.Controls.Add(c);    
     } 

     void b_Click(object sender, EventArgs e) 
     { 
      MessageBox.Show(c.Text.ToString()); 
     } 
    } 
} 

-1로 부하시 combox의 listindex 기본값을 지정하지 않으면 ""(공백)입니다 그래서 당신은 기본 값을 얻을 수있는 정확한 인덱스를 알고있는 경우 콤보 상자에 표시된 다음 해당 인덱스에 listindex를 설정하십시오.

아래 코드를 사용하면 런타임에 콤보 상자의 첫 번째 항목이 선택됩니다.

comboBox1.SelectedIndex = 0 (The first item in the combo box) 
1

데이터 바인딩은 보이지 않는 컨트롤에서 작동하지 않습니다. 나는 그것을 찾았다 here. 참조 용으로 보시려면 this MSDN thread

관련 문제