private void Window_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i <= 7; i++)
{
ColumnDefinition clDef = new ColumnDefinition();
RowDefinition rwDef = new RowDefinition();
clDef.MinWidth = 40;
clDef.MaxWidth = 40;
rwDef.MinHeight = 32;
rwDef.MaxHeight = 32;
grdAdtn.ColumnDefinitions.Add(clDef);
grdAdtn.RowDefinitions.Add(rwDef);
};
TextBox[,] fields=new TextBox[8,8];
for(int i=0;i<=7;i++){
for(int j=0;j<=7;j++){
fields[i,j]=new TextBox();
fields[i, j].Text = "test";
fields[i, j].Width = 40;
fields[i, j].Height = 32;
fields[i, j].Visibility = Visibility.Visible;
//Grid.SetColumn(fields[i, j], i);
}
}
}
With this I managed to add rows and columns to grid but I don’t see textboxes in grid fields. I need to make an array of textboxes so I can access them later and I don’t know how to make control array in Visual Studio editor so I tried to make the array when application is running.
Sorry for bad English.
Where you have commented out the SetColumn you need the following three lines:
So you were on the right track you just hadn’t added the text boxes to the design – all you’d done was create them and tried to set a column property.
Also note it’s best to avoid single letter variables – row and col for example would make this easier to read.
There may be another way to approach the problem as a whole but this will get your code working