Check for empty TextBox controls in VB.NET

前端 未结 7 1861
离开以前
离开以前 2020-12-06 13:01

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

7条回答
  •  遥遥无期
    2020-12-06 13:04

    A very simplistic approach would be to gather all the TextBox controls in a sequence using the Enumerable.OfType LINQ method and then iterate through it in a For Each loop:

    Dim textBoxes = Me.Controls.OfType(Of TextBox);
    
    For Each t In textBoxes
       If String.IsNullOrEmpty(t.Text) Then
           MsgBox("...")
           Exit For
       End If
    Next t
    

提交回复
热议问题