Solved

How to initialize a TabPage?

Posted on 2014-12-09
8
97 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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