Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i am trying to clear all the textboxes contained on all tabpages of a tabcontrol, which is enclosed inside a groupbox. what i have is probably very ugly (plus it doesn't work), so please help.....

(the line in red wouldn't compile)

Dim ctrl As Control
Dim ctrl1 As Control
Dim tBox As TextBox
Dim tBox1 As TextBox
Dim tbPage As TabPage

For Each ctrl In GroupBox2.Controls
   If TypeOf ctrl Is TextBox Then
       tBox = DirectCast(ctrl, TextBox)
       tBox.Clear()
   ElseIf ctrl Is TabControl1 Then
       Dim i As Integer
       For i = 0 To (Me.TabControl1.TabPages.Count - 1)
           [color=Red] For Each ctrl1 In Me.TabControl1.TabPages.Item(i)[/color]
                If TypeOf ctrl1 Is TextBox Then
                    tBox1 = DirectCast(ctrl1, TextBox)
                    tBox.Clear()
                End If

            Next
      Next
    End If
Next

Posted

Me.TabControl1.TabPages.Item(i) is not a collection of Control objects. You may want to try something like this:

 

Dim index As Integer = 0
For Each tab As TabPage In TabControl1.TabPages
 For Each ctrl As Control In tab.Controls
   If (TypeOf (ctrl) Is TextBox) Then
     ctrl.Text = String.Empty
   End If
 Next
Next

"Never ascribe to malice that which can adequately be explained by incompetence." -- Napolean Bonaparte

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...