Solved

How to initialize a TabPage?

Posted on 2014-12-09
8
81 Views
Last Modified: 2015-02-07
I'm having an issue with my tabpages. I have a particular Windows form that contains a TabControl with two TabPages. The first TabPage contains a DataGridView (DGV). When a User double-clicks on a row in the DGV, the data is loaded into various controls and variables and then the second TabPage is selected.

Now, on the second TabPage, I have several ComboBox (CB) controls. The way my logic is set up is that when the User selects a row from the first TabPage, certain values are are assigned to the "SelectedValue" of some CB's. When that happens, the SelectedIndex Event of the CB's fires and processes data accordingly. This works fine except for the very first time a row is selected from TabPage 1. The CB's SelectedIndex Event fires but the different controls don't get populated correctly. Once the second TabPage is shown, then this whole process works as it should. It's just on the initial row selection from the first TabPage.

Does anyone know why this happens? I hope I've explained this issue correctly.

Thanks!
0
Comment
Question by:BlakeMcKenna
  • 5
  • 3
8 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40489226
**Shot in the Dark**

Perhaps the second TabPage isn't being initialized properly?  In the Load() event of the Form, try iterating over all the TabPages and selecting them.  This should force initializing of the TabPage and all controls within it:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For i As Integer = 0 To TabControl1.TabCount - 1
            TabControl1.SelectedIndex = i
            Application.DoEvents()
        Next
        TabControl1.SelectedIndex = 0
    End Sub

Open in new window

0
 

Author Comment

by:BlakeMcKenna
ID: 40489320
That was a great idea but unfortunately it didn't work...
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40489371
Not sure then.  We may need to see some code to figure it...
0
 

Author Comment

by:BlakeMcKenna
ID: 40489390
What I'm trying to do is calculate a Date based on what a CB value is and then place it in a DateTimePicker control. That's the part that isn't working on the initial try. The following CB Event executes a Sub that calculates the Date Difference.

    Private Sub cmbInterval_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbInterval.SelectedIndexChanged
        'Debug.Print("cmbInterval_SelectedIndexChanged")

        Try
            EH.ErrorMessage = String.Empty

            If blnIsLoaded Then
                If cmbInterval.SelectedIndex <> -1 Then
                    iInterval_ID = CInt(cmbInterval.SelectedValue)

                    If cmbInterval.Text = String.Empty Then
                        decIntervalValue = 12
                    Else
                        decIntervalValue = cmbInterval.Text
                    End If

                    If blnCustomFormatApplied Then
                        blnCustomFormatApplied = False
                        dtCDCalDate.Format = DateTimePickerFormat.Short
                        dtCDExtensionDate.Format = DateTimePickerFormat.Short
                        dtCDCalDate.Value = Now
                        nextCalDate = Now.AddMonths(decIntervalValue)
                    Else
                        nextCalDate = DateAdd(DateInterval.Month, decIntervalValue, dtCDCalDate.Value)
                    End If

                    CalculateNextCalibrationDate(nextCalDate)

                    If EH.ErrorMessage = String.Empty Then
                        dtCDCalDate.Enabled = True
                        txtTraceabilityNO.Enabled = True
                        txtCombinedUncertainty.Enabled = True
                        dtCDCalDate.Focus()
                    End If
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "cmbInterval_SelectedIndexChanged() - " & ex.Message & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub
    '
    '
    '
    Private Sub CalculateNextCalibrationDate(ByVal nextCalDate As Date)
        'Debug.Print("CalculateNextCalibrationDate")

        Try
            EH.ErrorMessage = String.Empty

            If IsDate(dtCDCalDate.Value) Then
                dtNextCalibrationDate.Format = DateTimePickerFormat.Short
                nextCalDate = DateAdd(DateInterval.Month, decIntervalValue, dtCDCalDate.Value)
                dtNextCalibrationDate.Value = nextCalDate
            End If

        Catch ex As Exception
            EH.ErrorMessage = "cboCDSetDate_CheckedChanged() - " & ex.Message & "~E"
        End Try
    End Sub

Open in new window


The above code works everytime except for the initial row selection from the first TabPage.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40489401
You sure "blnIsLoaded" has been set the first time round?  Throw a Debug.Print() in there to make sure.
0
 

Author Comment

by:BlakeMcKenna
ID: 40489419
Positive...I've already run this through the debugger.
0
 

Accepted Solution

by:
BlakeMcKenna earned 0 total points
ID: 40585149
I just rearranged some code. I needed to change some design considerations but I finally got it working.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40595438
I just rearranged some code. I needed to change some design considerations but I finally got it working.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now