Barbulescu Mihai

Barbulescu Mihai

  • NA
  • 33
  • 11.4k

using ArrayList to create dynamic tabcontrol pages

Jan 30 2009 12:33 PM
I have the following function reading XML file:

    Function ReadProductsCategories(ByVal XMLFile As String) As ArrayList
        Dim ReaderArray As New ArrayList
        Dim Reader As XmlTextReader = New XmlTextReader(XMLFile)
        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Text
                    'Store values in the arraylist container
                    ReaderArray.Add(Reader.Value)
            End Select
        Loop
        'Return the arraylist container
        Return ReaderArray
    End Function

The following Sub is using it:

Private Sub LoadAllProductsCategories()
        Dim i As Integer
        Dim ItemList As New ArrayList
        Dim AllProdTabPage As New TabPage

        ItemList = ReadProductsCategories("allprodcat.xml")
        For i = 0 To ItemList.Count - 1
            AllProdTabPage.Name = "tab" & ItemList.Item(i)
            AllProdTabPage.Text = ItemList.Item(i)
            TabControl2.Controls.Add(AllProdTabPage)
        Next
    End Sub

The problem is that the first tabpage text is replaced with the last tabpage text. In this way I get the last tabpage 2 times, in the first position (where there should be completely other tabpage, the real one, the first one) and in the last position (correct)

Any ideea why I get this problem ? I have tested the XML reading by displaying messageboxes with each arraylist element and all is fine, the problem is when actually creating the tabpages.

Looking forward to your support on this one!

Answers (1)