?
Solved

How to initialize a TabPage?

Posted on 2014-12-09
8
Medium Priority
?
99 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 86

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 86

Expert Comment

by:Mike Tomlinson
ID: 40489371
Not sure then.  We may need to see some code to figure it...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
LVL 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

719 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