Public Class Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lstPatientNames.Items.Add(Names())
End Sub
End Class
我想让列表框显示数组:names()。但是我收到错误:“索引数小于索引数组的维数”。数组没有设定数量的元素,因为用户在输入数据时决定了数组的元素数量。那么我的代码应该怎么样?
由于
填充数组:
Public Class Form2
Dim i As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMainMenu.Click
Me.Close()
End Sub
Private Sub btnEnterPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterPatient.Click
ReDim Preserve Names(0 To i)
Names(i) = txtPatientName.Text
ReDim Preserve Heights(0 To i)
Heights(i) = txtPatientHeight.Text
ReDim Preserve Weights(0 To i)
Weights(i) = txtPatientWeight.Text
i = i + 1
Label1.Text = i
End Sub
End Class
答案 0 :(得分:0)
List1.Items.Clear
List1.Items.AddRange(al1.ToArray)
OR,
List1.Items.Clear
For each obj as object in al1
List1.Items.Add(obj)
Next
或者,
List1.Items.Clear
For i as Integer = 0 to al1.count-1
List1.Items.Add(al1(i))
Next
您必须在Arraylist中覆盖对象的ToString。您必须使列表框字体成为固定字体,以便您可以进行间距(Courier New) 我建议使用Generic.List(Of clsCustomer),但是如果不在作业中,你将被卡在角斗车中的对象中。 然而,这仍然留下了解决这一任务的大量细节 祝你好运。