更新时间:2023-02-10 14:49:51
我不确定您的教授为什么指示您使用任意数组,但这是另一个问题.以下代码反映了所需的行为:
I´m not sure why your professor instructs you to use an arbitrary array but that´s another question. The following code reflects the desired behavior:
Public Class Form1
Dim ArrayofNames() As String
Private Sub Retrievebtn_Click(sender As Object, e As EventArgs) Handles Retrievebtn.Click
Dim idxRetreive = Integer.Parse(TextBox2.Text)
TextBox3.Text = ArrayofNames(idxRetreive)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
syncItemArray()
End Sub
Private Sub Addbtn_Click(sender As Object, e As EventArgs) Handles Addbtn.Click
Dim newItem = TextBox1.Text
ListBox1.Items.Add(newItem)
syncItemArray()
End Sub
Private Sub syncItemArray()
ReDim ArrayofNames(ListBox1.Items.Count - 1)
ListBox1.Items.CopyTo(ArrayofNames, 0)
End Sub
End Class