我有两个ListBox1和ListBox2.我已ListBox2通过选择ListBox1项目将项目插入到以下代码中:
da6 = New SqlDataAdapter("select distinct(component_type) from component where component_name='" & ListBox1.SelectedItem() & "'", con)
da6.Fill(ds6, "component")
For Each row As DataRow In ds6.Tables(0).Rows
ListBox2.Items.Add(row.Field(Of String)("component_type"))
Next
Run Code Online (Sandbox Code Playgroud)
但是当我重新选择另一个项目ListBox1然后ListBox2显示预装项目和现在加载的项目.我只希望现在加载的项目显示在列表框中.我使用了这段代码,但问题没有解决:
For i =0 To ListBox2.items.count - 1
ListBox2.Items.removeAt(i)
Next
Run Code Online (Sandbox Code Playgroud)
或者
listbox2.items.clear()也没有工作..
如何清除所有项目ListBox2?
vb.net ×1