BlakeMcKenna
asked on
How to initialize a TabPage?
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!
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!
ASKER
That was a great idea but unfortunately it didn't work...
Not sure then. We may need to see some code to figure it...
ASKER
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.
The above code works everytime except for the initial row selection from the first TabPage.
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
The above code works everytime except for the initial row selection from the first TabPage.
You sure "blnIsLoaded" has been set the first time round? Throw a Debug.Print() in there to make sure.
ASKER
Positive...I've already run this through the debugger.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just rearranged some code. I needed to change some design considerations but I finally got it working.
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:
Open in new window