how to disable the 50 textboxs in one line coding

It's possible in C# using an anonymous method:
VB.NET:
Array.ForEach(this.Controls.OfType<TextBox>().ToArray(),
              delegate(TextBox field) { field.Enabled = false; });
or a lambda expression:
VB.NET:
Array.ForEach(this.Controls.OfType<TextBox>().ToArray(),
              (TextBox field) => field.Enabled = false );
As far as I can see it's not possible in VB because lambda expressions must return a value. VB 2010 will change that so this will be valid in that version:
VB.NET:
Array.ForEach(Me.Controls.OfType(Of TextBox).ToArray(), _
              Sub(field As TextBox) (field.Enabled = False))
In VB 2008 though, you'll have to either use a loop:
VB.NET:
For Each field In Me.Controls.OfType(Of TextBox)()
    field.Enabled = False
Next
or else declare a method to invoke via an Action delegate:
VB.NET:
        Array.ForEach(Me.Controls.OfType(Of TextBox).ToArray(), _
                      AddressOf DisableTextBox)


    Private Sub DisableTextBox(ByVal field As TextBox)
        field.Enabled = False
    End Sub
 
Back
Top