*忽略了一个事实,这是一个可怕的设计...
变化:
If ListBox1.SelectedIndex = 2 Then ListBox2.Items.Add("60137" & ListBox2.Items.Add("60138"))
要:
If ListBox1.SelectedIndex = 2 Then
ListBox2.Items.Clear
ListBox2.Items.Add("60137")
End If
这是一种替代方法:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim petA As New Pet
petA.Name = "Puss in Boots"
petA.Species = "Cat"
ListBox1.Items.Add(petA)
Dim petB As New Pet
petB.Name = "Nemo"
petB.Species = "Fish"
ListBox1.Items.Add(petB)
Dim petC As New Pet
petC.Name = "Rango"
petC.Species = "Lizard"
ListBox1.Items.Add(petC)
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedIndex <> -1 Then
Dim P As Pet = DirectCast(ListBox1.SelectedItem, Pet)
Label1.Text = P.Species
End If
End Sub
End Class
Public Class Pet
Public Name As String
Public Species As String
Public Overrides Function ToString() As String
Return Name
End Function
End Class
你为什么使用ListBox作为rela特德项目?列表框用于显示用户可以从中选择的多个项目。它看起来像一个标签将是一个更好的选择。 – 2014-12-04 03:36:54