Dynamic Add User Control Object To The Tab Control

cheer

New member
Joined
Feb 25, 2009
Messages
1
Programming Experience
3-5
Anyone can suggest what's wrong to the code below as the User Control objects ONLY appear in the first tab and NOT in the balance tabs ?

1) User Control name - usRFQDetail
2) Tab Control name - tcRFQDetail

VB.NET:
Dim tcPage As New TabPage
Dim ucRFQDetailInstance As usRFQDetail() = New usRFQDetail(100) {}

Dim sdrReader As SqlDataReader = cmdReader.ExecuteReader(CommandBehavior.CloseConnection)

With sdrReader
    If .HasRows Then
        ucRFQDetailInstance(intTotalTab) = New usRFQDetail
        .Read()
        tcRFQDetail.TabPages(intCurrentTab).Text = .GetString(.GetOrdinal("DrawingNo"))
        While .Read
            intCurrentTab += 1
            tcPage.Text = .GetString(.GetOrdinal("DrawingNo"))
            tcRFQDetail.TabPages.Add(tcPage) tcRFQDetail.TabPages(intCurrentTab).Controls.Add(ucRFQDetailInstance(intCurrentTab))
        End While
 
A tabpage instance can only be one place at a time. You have only created one tabpage that you move around, basically.
 
I'm new but...

I'm pretty new, so this may be a dumb way of doing things, but the way i solved this problem was to allow the reader to fill a an arraylist, then for each entry in the array list if built a tab using a seperate sub. So its kinda like this:

VB.NET:
    Private Sub ConsoleMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim dList As New ArrayList
        Dim dReader As SqlDataReader
        Dim cmd As New SqlCommand
        Dim sql As String = "YOUR SQL STATEMENT HERE"

        conn.ConnectionString = cstring

        Try
            conn.Open()
            Try
                cmd.Connection = conn
                cmd.CommandText = sql
                dReader = cmd.ExecuteReader
                While dReader.Read
                    dList.Add(dReader.tostring())
                End While
                dReader.Close()
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
            conn.Close()
            If dList(0) <> "" Then
                Dim name As String
                Dim tabNum As Integer = 0
                For Each name In dList
                    buildtabs(name, tabNum)
                    tabNum += 1
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        Finally
            conn.Dispose()
        End Try

    End Sub

As you saw above each item in the dList call buildtabs with a string and int:

VB.NET:
Private Sub buildtabs(ByVal tabName As String, ByVal tabNum As Integer)
            
        Dim ctrlName as new [I]controltype[/I]
        'in my case i also added a string that was just tabname.trim to avoid the whitespace in SQL

        With tcRFQDetail
            .TabPages.Add(tabName)
        End With

        'set your ctrlName attributes here

        ReportsTabs.TabPages(tabNum).Controls.Add(ctrlName)

    End Sub
 
Back
Top