2016-11-25 44 views
0

我一直在想如何循環我的文本框有一個整數作爲一個值,並將其插入到一個列表視圖。我的文本框從Textbox2.Text開始,並以Textbox41.Text結尾。事情是我需要檢查每個2文本框(例如textbox2和textbox3)並插入一個列表視圖。我不知道如何循環其他文本框。每個2文本框的循環

Try 
    If TextBox2.Text <> Nothing And TextBox3.Text <> Nothing Then 
     Pid += 1 
     At = TextBox2.Text 
     Bt = TextBox3.Text 

     Table = ListView1.Items.Add(Pid) 
     With Table 
     .SubItems.Add(At) 
     .SubItems.Add(Bt) 
     End With 

     TextBox2.Text = Nothing 
     TextBox3.Text = Nothing 
    End If 
Catch ex As Exception 
    MsgBox("Must be numbers!") 
End Try 
+0

請添加更多信息的問題。你試過什麼了? –

+0

您的應用程序是Windows窗體還是Web? –

+0

我的應用程序是Windows窗體:) – Yliah

回答

0

如果您的應用程序是Windows窗體,這是你如何能得到的所有整數值...

Dim intList As New List(Of Integer)() 
For Each c As Control In Me.Controls 
    If c.GetType Is GetType(TextBox) Then 
     Dim txtControl As TextBox = CType(c, TextBox) 
     If Integer.TryParse(txtControl.Text, 0) Then 
      intList.Add(Convert.toInt32(txtControl.Text)) 
     End If 
    End If 
Next 
+0

嗨。在第四行有一個錯誤:)謝謝btw – Yliah

+0

謝謝!但是c中仍然存在錯誤..(c,0) – Yliah