首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

请教怎么遍历textbox

2012-02-27 
请问如何遍历textbox?各位老牛好!俺想问问,假设俺有textbox1,textbox2,......textbox9,textbox10等十个tex

请问如何遍历textbox?
各位老牛好!俺想问问,假设俺有textbox1,textbox2,......textbox9,textbox10等十个textbox,
俺要如何去遍历这十个textbox的text是否为空呢?俺要求只要有一个或一个以上的textbox不为空,就
msgbox出来!俺要vb.net的代码哦!万分感激!!!

[解决办法]
TEXTBOX 遍历? 好像只能单个单个判断吧..可能本人才疏学浅,关注中...
[解决办法]
Dim 计数器 As Integer
If txt_bz.TextLength <> 0 Then
For i = 0 To txt_bz.TextLength
If txt_bz.Text <> "" Then
计数器++
End If
Next
End If
[解决办法]

VB.NET code
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        CheckValidForTextBox(Me.Controls)    End Sub    Private Sub CheckValidForTextBox(ByVal collection As Control.ControlCollection)        For Each ctr As Control In collection            If TypeOf ctr Is TextBox Then                Dim textbox As TextBox = CType(ctr, TextBox)                Dim index As Integer = Integer.Parse(textbox.Name.Substring(7))                If index > 0 AndAlso index < 11 Then                    If String.IsNullOrEmpty(textbox.Text) Then                        MsgBox("hi")                        ctr.Select()                        Exit For                    End If                End If            End If        Next    End Sub
[解决办法]
定义公共变量 
Dim w_max As Integer = 3 ’我只用了三个作试验,根据需要自己定义
 Dim t_b(w_max) As System.Windows.Forms.TextBox
 Dim i As Integer

在判断的地方写上
 For i = 0 To 2
If t_b(i).Text = "" Then
MsgBox("3")
Exit For
End If
 Next
目前时只要发现为空就弹出msg
不知道是不是lz想要的?

热点排行