Solved

How to initialize a TabPage?

Posted on 2014-12-09
8
89 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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