Ive got a Form application in VB.NET.
I have many text boxes on one form (about 20). Is there anyway to check them all at once to see if they are empty instead of wr
You could also use LINQ:
Dim empty =
Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0)
If empty.Any Then
MessageBox.Show(String.Format("Please fill following textboxes: {0}",
String.Join(",", empty.Select(Function(txt) txt.Name))))
End If
The interesting method is Enumerable.OfType
The same in query syntax(more readable in VB.NET):
Dim emptyTextBoxes =
From txt In Me.Controls.OfType(Of TextBox)()
Where txt.Text.Length = 0
Select txt.Name
If emptyTextBoxes.Any Then
MessageBox.Show(String.Format("Please fill following textboxes: {0}",
String.Join(",", emptyTextBoxes)))
End If