Access CheckBox controls

Hi...Can i please have a guideline on how to access a checkBox within controls?
Form->TabControl1->TabPage2->GroupBox->CheckBox (Change the CheckState)
There is No Problem when i am trying access the CheckBox in TabPage1
But when i try in TabPage2 nothing happens..
LVL 18
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAsked:
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
Try shifting focus to tabpage2 before accessing the checkbox. Otherwise, you can put this logic in tabpagechanging event and set the controls when tabpage2 gets focused by user.
Is tabpage2 in focus when you try? Controls on tabpages not shown yet are not created unless that tabpage gets focus.
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
No TabPage1 is the one it has is that the reason why? i know the theory but i imagine that because the controls are placed in the document outline in this siries it is possible to have an access
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
Ok...I will use then the TabControl1.Selected Event and acess then the desire Control...
Thank you Nasir!
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
Just for info final code ....
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
            If DirectCast(sender, TabControl).SelectedIndex = 1 Then 'Is the Second Tabpage
                For i As Integer = 1 To 3
                    For Each ctl As Control In Me.TabPage2.Controls.Find("Page2GroupBox" & i, True)(0).Controls
                        If TypeOf ctl Is CheckBox Then
                            If Not DirectCast(ctl, CheckBox).CheckState = CheckState.Checked Then
                                DirectCast(ctl, CheckBox).CheckState = CheckState.Unchecked
                            End If
                        End If

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "ErrorOccured", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.