我正在使用VB 2010 express。如何从文本框中的值创建列表框中的数字列表。例如,如果文本框为“15”,则列表框将为“1”,“2”,“3”....“15”我希望每个数字在列表框中位于其自己的行上。 感谢。
答案 0 :(得分:1)
你可以这样做:
Private Sub PopulateList(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim list As String() = New String(-1) {}
Dim str As String = Me.TextBox1.Text
Dim count As Integer = 0
Integer.TryParse(str, count)
If (count > 0) Then
list = New String((count - 1)) {}
For i As Integer = 0 To (count - 1)
list(i) = (i + 1).ToString()
Next
End If
Me.ListBox1.Items.Clear()
Me.ListBox1.Items.AddRange(list)
End Sub