Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing txt fields in tab control

Status
Not open for further replies.

allanmc10

Programmer
Feb 23, 2006
39
GB
I have set up a Tab Control with lots of txt fields and when i click a button i want to clear the txt fields

Is their anyway that i can do this like in a for loop or do i have to call each individual txt field.

Cheers

big AL
 
Code:
        Dim tp As TabPage = Nothing
        Dim c As Control = Nothing

        For Each tp In Me.TabControl1.TabPages
            For Each c In tp.Controls
                If TypeOf c Is TextBox Then
                    DirectCast(c, TextBox).Text = String.Empty
                End If
            Next
        Next


** It will clear all textboxes in all tabpages.

Regards
 
TipGiver,

In the past I discovered that the only way I was able to get that to work was
Code:
Dim tp As TabPage = Nothing
Dim c As Control = Nothing

For Each tp In Me.TabControl1.TabPages
   For Each c In tp.Controls
     If [b]c.GetType[/b] Is [b]GetType([/b]TextBox[b])[/b] Then
       DirectCast(c, TextBox).Text = String.Empty
     End If
   Next
Next
The bold sections are what I needed to add to get it to work so now thats what I use.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT * FROM Users WHERE clue > 0
0 Rows Returned

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top