Question : How to access and manipulate multiple dynamically created gridcontrols and populate them from a CSV file

Tabpages are dynamically created depending on the number of products in a CSV file.  Each tabpage has its own unbound grid control.  I need to populate these grids with data from another CSV file and I am having problems accessing each grid to add rows, columns etc.   Can anybody help me please... I am using vb.net 2008

Answer : How to access and manipulate multiple dynamically created gridcontrols and populate them from a CSV file

Assume that on your form, you have a TabControl (named TabControl1) with number of TabPages, each of which holds a DataGridView control (named DataGridView1 on the first TabPage) to display data from a CSV file.
Then you can access the DataGridView on the first TabPage by the following code:

       Dim oDGW As DataGridView = CType(TabControl1.TabPages(0).Controls("DataGridView1"), DataGridView)
       Dim i As Integer = o.Rows.Count
       Dim j As Integer = o.Columns.Count
        'Then you can add rows, columns using the following code
       oDGW .Rows.Add()
       oDGW .Columns.Add("NewColumn", "New Column Header")

Or if there is only one control (i.e., a DataGridView) on each TabPage, you can use the following code to get the control:

       Dim oDGW As DataGridView = CType(TabControl1.TabPages(0).Controls(0), DataGridView)

Random Solutions  
 
programming4us programming4us