Robin
Robin

Reputation: 165

Contents of tab control aren't loaded unless clicked on

I have a VB app with 8 tabs.

This application edit/add stuff and print a report. The first tab is defaulted.

However, I have certain constraints on most of the tabs that need be passed as parameters through the report so If I run run the report before clicking on the tabs, it won't get the value. These controls I am trying to get are just Checkboxes, running the report sends all False, and I know there are checked ones. I am unsure of how to get the correct value without having to click on the tabs itself.

The code below is all for my main form..

    Public Sub New(ByVal session As UserSession, ByRef caller As Form)
    InitializeComponent()
    thisSession = session

    IncidentControl1.FormSession = session
    PersonsControl1.FormSession = session
    VictimControl1.FormSession = session
    VehicleControl1.FormSession = session
    UseOfForceControl1.FormSession = session
    NarrativeControl1.FormSession = session

    callingForm = caller
    blnHome = True
End Sub

Private Sub UseofForceFormv1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Try
        InitializeDataStructures()

        LoadReport()
        CreateDataRelations()
        SetUpTabControls()
        SetupDataBindings()
        SetStatusLabels()
        addHandlers()
        thisSession.sigAdmin

        TabControl1.SelectTab(1) ' these 2 lines fixed my issue
        TabControl1.SelectTab(0)

End Sub

Private Sub SetUpTabControls()
    LocationTab1.SetupTab(subLocationDT, thisSession, thisSession.reportID, dsMain)
    ActorTabv11.SetupTab(dsMain, thisSession)
End Sub

This is the tab within my main form..

Public Sub SetupTab(ByRef formDataSet As DataSet, ByVal session As UserSession)
    incidentReportDS = formDataSet
    thisSession = session

    thisSession = session
    'incidentReportDS = incidentReportDS
    dataUtil = New DAL.DataUtil

    bcActor = BindingContext(vwActor)


    vwIncidentArrest = Actors(0).IncidentArrest()


    SetupFieldAvailableValues()

    SetUpDataBindings()

    AddEventHandlers()
    bcActor_PositionChanged(Me, EventArgs.Empty)

End Sub

EDIT: I added TabControl1.SelectTab() method at the end of my main form load to select the tabs I wanted then just select the first one, causing them all to load.

Upvotes: 2

Views: 4985

Answers (1)

This behavior (issue) is to be expected. To quote MSDN:

"Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown."

Solution

To resolve this issue: "make each tab page active before making the form visible."

Upvotes: 3

Related Questions