In VB.NET, I have a form with 3 DataGridView controls. The routine used to fill them does quite a bit of work, and I thought to use a single routine for all of them, and simply make the name of my DataGridView variable to be dynamic:
For each dtr As Datarow in MyDataTable.Rows
'/ bunch of code here to format data and such
Dim dg As DataGridView
dg = Controls("dg" & dtr("Category"))
'/ more code to format the datagrid
However, the dg variable always resolves to Nothing. The name of the control is correct - for example, dtr("Category") contains a value of "Park", and I have a DataGridView control named "dgPark". I've tried using this:
Dim dg As New DataGridView
With the same results ...
How can I do this at runtime? I have only 3 now, and I can hardcode it, but it seems the code above should work.