I am creating a grid of textboxes inside a groupbox in vb.net. they are all of a uniform width,height, font etc.. the code I currently have is this:
Dim new_cell As New TextBox
With new_cell
.Multiline = True
.Width = cell_width
.Height = cell_height
.Font = ("arial", 12)
End With
For j = 0 To N
For i = 0 To M
new_cell.Left = (i * cell_width) + i
new_cell.Top = (j * cell_width) + j
space.Controls.Add(new_cell)
Next
Next
where M,N are the grid size and space is the groupbox. this was supposed to create the whole grid however it only creates one textbox at the bottom corner. This is because the changes to new_cell on the next iteration of the loop affect the previous control and so a new control is never added. I could replace the single textbox with an array and then loop through and add each element of the textbox array to the groupbox. this however creates ugly code and seems inefficient( what with the repeated properties for each cell) and so I was wondering whether there was a way to add a control to a groupbox and then disassociate (or something) the textbox variable and the textbox added to the groupbox.