Software Engineer, Equity Strategist, Polymath.
Posts tagged textbox
Clearing all textboxes on a Form
17 years
by Ray Tawil
in Visual Basic.Net
Do you have a form that has a lot of textboxes?
do you want to clear all those textboxes for example when there is a new?
this is the old scenario:
[codesyntax lang=”vbnet”]
TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = ""
[/codesyntax]
etc…………
this is my idea:
[codesyntax lang=”vbnet”]
Sub ClearForm(ByVal frm_name As Form) Dim Contrl As Control For Each Contrl In frm_name.Controls If (TypeOf Contrl Is TextBox) Then Contrl.Text = "" Next Contrl End Sub
[/codesyntax]
this is my friend samir ibrahim‘s idea, compatible with “.net framework 3.5 +”
[codesyntax lang=”vbnet”]
For Each _Ctrl As Control In Me.Controls.OfType(Of TextBox)() _Ctrl.Text = "" Next
[/codesyntax]
The second idea is more optimized with same result.
Of course my idea is cooler because i made it ![]()
you just need to pass the form name to the function & it will clear the form for you, this will save your fingers extensive redundant typing ![]()
![]()
![]()
![]()
![]()