for
(
int
j
=
0
; j
<
numrows; j
++
)
{
RowDefinition rd
=
new
RowDefinition();
LayoutRoot.RowDefinitions.Add(rd);
ColumnDefinition cd
=
new
ColumnDefinition();
LayoutRoot.ColumnDefinitions.Add(cd);
for
(
int
i
=
0
; i
<
numcells; i
++
)
{
TextBox tb
=
new
TextBox();
tb.Width
=
110
;
tb.Height
=
30
;
tb.Text
=
"
row
"
+
j.ToString()
+
"
, cell
"
+
i.ToString();
LayoutRoot.Children.Add(tb);
LayoutRoot.SetValue(Grid.ShowGridLinesProperty,
true
);
//
显示网格
tb.SetValue(Grid.ColumnProperty, i);
tb.SetValue(Grid.RowProperty, j);
}
}
转自:http://www.cnblogs.com/star250/archive/2009/04/19/1439181.html