首页 > 解决方案 > 检查分组框内的多个控件类型是否为空并显示空控件的标签

问题描述

如前所述,我需要检查组框中的所有字段是否为空,然后显示一个消息框,显示空字段的标签。

问题是我在这个框中有多种类型的控件,包括:TextBox、NumericUpDown 和 DatePicker。

我想知道是否有比我在下面做的更简单的方法。

        If BenchQtyCombo.Text = 1 Then
            Dim B1emptyTextBoxes =
            From txt In Bench1_Combo.Controls.OfType(Of TextBox)()
            Where txt.Text.Length = 0
            Select txt.Tag

            Dim B1emptyNumericBox =
            From num In Bench1_Combo.Controls.OfType(Of NumericUpDown)()
            Where num.Value = 0
            Select num.Tag

            If B1emptyTextBoxes.Any Or B1emptyNumericBox.Any Then
                MessageBox.Show(String.Format("Please Complete the Following Required Fields:" & vbCrLf & vbCrLf & "{0}", String.Join(", ", B1emptyTextBoxes, B1emptyNumericBox)))

            End If
        End If

我也有B1emptyTextBoxes, B1emptyNumericBox在消息框中显示标签的问题,因为我得到这个字符串而不是标签

我还没有包含日期​​选择器的代码,这将类似于Where DatePicker.Date > Today代码,直到我得到这个工作。

任何建议将不胜感激。

标签: vb.netselectdatepickertextboxnumericupdown

解决方案


您将加入 2 个列表以将它们显示在MessageBox. 您需要单独加入这些列表的内容,然后加入这些字符串。

您的MessageBox字符串将需要:

String.Join(", ", String.Join(", ", B1emptyTextBoxes), String.Join(", ", B1emptyNumericBox))

推荐阅读