The code below works for one tabpage (x = to node_list.count - 2) but does not work for more than one tabpage (x = to node_list.count - 1). There are only two tabs at the moment but I expect there to be, on average 5, but could be up to 10 or more.
Private Sub UF_DEF_COL_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim doc As New XmlDocument()
doc.Load("C:\Users\geoff.warrington\Documents\Visual Studio 2010\Projects\Project Register\Project Register\Tab_List.xml")
Dim root As XmlElement = doc.DocumentElement
Dim node_list As XmlNodeList = root.GetElementsByTagName("Tab")
Me.SHEET_DEF.TabPages.Remove(Register)
Dim x As Integer
Dim Y As Integer
Dim TB As New TabPage
For x = 0 To node_list.Count - 2
Dim No_Cols As Integer = node_list(x).ChildNodes.Count - 1
Me.SHEET_DEF.TabPages.Add(TB)
With TB
.Location = New System.Drawing.Point(4, 22)
.Name = node_list(x).FirstChild.InnerText
.Padding = New System.Windows.Forms.Padding(3)
.Size = New System.Drawing.Size(805, 172)
.TabIndex = x + 1
.Text = node_list(x).FirstChild.InnerText
.UseVisualStyleBackColor = True
End With
Dim Col_Data_Grid = New DataGridView()
With Col_Data_Grid
.Name = node_list(x).FirstChild.InnerText & "DGV"
.ColumnCount = node_list(x).ChildNodes.Count - 1
.Location = New Point(8, 8)
.Size = New Size(1000, 25)
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.AutoSizeColumnsMode = _
DataGridViewAutoSizeColumnMode.DisplayedCells
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.Dock = DockStyle.Fill
.Visible = True
End With
For Y = 1 To No_Cols
Col_Data_Grid.Columns(Y - 1).Name = node_list(x).ChildNodes(Y).InnerText
Next
Col_Data_Grid.Parent = Me.SHEET_DEF.TabPages(x)
Me.SHEET_DEF.TabPages(x).Controls.Add(Me.Col_Data_Grid)
Next
End Sub
Friend WithEvents Register As System.Windows.Forms.TabPage
Friend WithEvents Col_Sel As System.Windows.Forms.DataGridView
Friend WithEvents ID As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents Col_Data_Grid As System.Windows.Forms.DataGridView