如何检查数组中所有 TextBox 控件的 Tag 属性?
我想要这样的东西:
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-Method
If allTextBoxes.All(Function(t) t.Tag.ToString = "2") Then
'All Tags are "2"
End If
为了避免NullReferenceException https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it,如果其中一个文本框是Nothing
您可以添加额外的检查:
If allTextBoxes.All(Function(t) t IsNot Nothing AndAlso t.Tag.ToString = "2") Then
'All Tags are "2"
End If
或者您可以使用空条件运算符 https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/null-conditional-operators(Visual Basic v.14 或更高版本)
If allTextBoxes.All(Function(t) t?.Tag.ToString = "2") Then
'All Tags are "2"
End If
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)