2009-08-20 5 views
0

테이블 (유형 테이블)에 texbox를 추가하고 있지만 추가 할 수 없습니다. 나는 각 행에 하나 이상의 셀을 추가 할 수 없다.TextBox 테이블이 deisred로 표시되지 않습니다.

TextBox[] tx = new TextBox[10]; 
     TableCell[] tc = new TableCell[10]; 

     TableRow[] tr = new TableRow[10]; 

     for (int i = 0; i < 10; i++) 
     { 
      tx[i] = new TextBox(); 
      tc[i] = new TableCell(); 
      tc[i].Controls.Add(tx[i]); 
     } 

     for (int i = 0; i < 10; i++) 
     { 
      tr[i] = new TableRow(); 
      tr[i].Cells.Add(tc[i]); 
     } 

     for (int i = 0; i < 10; i++) 
      Table1.Rows.Add(tr[i]); 

은 10 개 행 각각은 단 1 전지

+0

출력을 어떻게 하시겠습니까? 1 행에 10 개의 셀이 있습니까? – BigBlondeViking

+0

아니요, 10 x 10 –

+0

이어야합니다. 텍스트 상자, 셀 및 행을 테이블에 삽입 한 후에 액세스해야하기 때문에 저장하고 있습니까? – BigBlondeViking

답변

0

세포가 구별되어야합니다 : 나는 10 개의 세포 만 만들 필요가 없습니다!

TextBox[] tx = new TextBox[100]; 
     TableCell[] tc = new TableCell[100]; 

     TableRow[] tr = new TableRow[10]; 

     for (int i = 0; i < 100; i++) 
     { 
      tx[i] = new TextBox(); 
      tc[i] = new TableCell(); 
      tc[i].Controls.Add(tx[i]); 
     } 

     int x = 0; 
     for (int i = 0; i < 10; i++) 
     { 
      tr[i] = new TableRow(); 
      for (int j=0; j < 10; j++) 
      { 
       tr[i].Cells.Add(tc[x++]); 
      } 
     } 


     for (int i = 0; i < 10; i++) 
      Table1.Rows.Add(tr[i]); 
+0

2 차원 배열에 의해 수행되는 것이 더 좋습니다. –

1

처럼 제공이에 대한 내부 루프가 필요하기 때문에 :

for (int i = 0; i < 10; i++) 
{ 
    tr[i] = new TableRow(); 
    tr[i].Cells.Add(tc[i]); 
} 

이 시도 :

for (int i = 0; i < 10; i++) 
{ 
    tr[i] = new TableRow(); 
    for (int x = 0; x < 10; x++) 
    { 
     tr[i].Cells.Add(tc[x]); 
    } 
} 
+0

이제 10 개의 셀이 있지만 단 하나의 행이 있습니다! –

0

귀하의 루프를 당신에게 10x10 테이블을 제공하도록 설정되지 않았습니다

Table table = new Table(); 
TableRow tr = null; 
TableCell tc = null; 
for (int i = 0; i < 10; i++) 
{ 
    tr = new TableRow(); 

    for (int j = 0; j < 10; j++) 
    { 
     tc = new TableCell(); 

     tc.Controls.Add(new TextBox()); 

     tr.Cells.Add(tc); 
    } 

    table.Rows.Add(tr); 
} 
관련 문제