I am creating a DataGridView dynamically at run-time, and cant seem to be able to instantiate it as an object during casting in another (Form1) subroutine, so that I can change row labels.
Here is how I define the DataGridView in the Form1 Load procedure:
Dim DataGridView1 As New DataGridView
Later, in a subroutine, when I want to change the row labels (numrows is the number of rows), I can't get the cast to work correctly because the cast won't allow me to use "As New" -- as follows:
Dim DataGridview1 As DataGridView = CType(Me.Controls("DataGridView1"), DataGridView)
For i = 1 To numrows
DataGridview1.Columns.Add(i, "V" & i)
What is the correct way instantiate as an object a control that was spawned dynamically?