检查数组中每个 TextBox 的标签 [英] Checking the Tags of each TextBox in an array

查看:21
本文介绍了检查数组中每个 TextBox 的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查数组中所有 TextBox 控件的 Tag 属性?
我想要这样的东西:

How do I check the Tag property of all the TextBox controls in an array?
I want something like this:

If textBox.Tag And textbox2.Tag And textbox21.Tag And
   textbox22.Tag And textbox23.Tag And textbox24.Tag = "2" Then

这是我的文本框数组:

Dim allTextboxes() As TextBox = {textBox, narNaslov, narPersona, narDani, narPersona2,
                                 kupIme, kupAdresa, kupKontakt, uvBroj, uvDatum, uvIznos,
                                 uvAvans, uvRok, uvNacin, datumTbox} 

推荐答案

您可以使用 LINQ All()-

You can use the LINQ All()-Method

If allTextBoxes.All(Function(t) t.Tag.ToString = "2") Then
    'All Tags are "2"
End If

<小时>

为了避免 NullReferenceException,如果其中一个文本框是 Nothing,您可以添加额外的检查:


To avoid a NullReferenceException, if one of the textboxes is Nothing you can add an additional check:

If allTextBoxes.All(Function(t) t IsNot Nothing AndAlso t.Tag.ToString = "2") Then
    'All Tags are "2"
End If

或者您可以使用 空条件运算符(Visual Basic v. 14 或更高版本)

Or you can use the Null-conditional operator (Visual Basic v. 14 or greater)

If allTextBoxes.All(Function(t) t?.Tag.ToString = "2") Then
    'All Tags are "2"
End If

这篇关于检查数组中每个 TextBox 的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆