0

我想知道要在我的项目中使用的控件是 Listview 还是 listbox ???。我的项目中有一个组合框控件我想要做的是,当我在组合框中选择 1 个项目时,它会自动添加到列表框或列表视图中,当我选择超过 1 个项目时,我想将其添加到列表框或列表视图中的换行符上。 ..

是不是很简单,请帮我在列表框或列表视图中做到这一点。谢谢!

4

2 回答 2

0
Listbox > Is for viewing too but user can select it
Listview > Is for viewing only, user cannot select also it viewing by five view directly cause it's for viewing only

如果您的项目希望从 Combobox 选择的内容中查看列表,那么您只需选择列表视图,但如果您还想查看用户可以选择它,最好使用列表框,这取决于您。您还可以通过将鼠标光标聚焦到工具上来了解工具的工作原理,然后它会弹出一个工具提示,说明该工具的用途。

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        ListView1.Items.Add(ComboBox1.SelectedIndex)
    End Sub

这是在列表视图中查看您在组合框中选择的代码的代码

要清除列表视图或列表框中的所有项目,只需写入您的 form_load

Listview.items.clear

为什么我说在表单加载中,因为列表只是为了查看,当然每次表单开始运行时,它都会需要空白列表,所以最好放在表单加载中

更新

删除列表框中选定的索引

 Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        ListBox1.Items.Remove(ListBox1.SelectedItem)
    End Sub
于 2013-04-03T01:40:10.127 回答
0

可以通过多种方式选择 ListView 项目 在 ListBox 的“属性”窗口中,激活属性允许通过单击或单击两次来激活项目。这是如何使用所选项目的示例

    If Me.ListView1.SelectedItems.Count = (1) Then
    'Declare the selected item
     Dim lviSelectedItem As ListViewItem = Me.listView1.SelectedItems(0)
    'Now you can use it
    lblLabel1.Text = lviSelecetedItem.Text

    Else
    lblLabel2.Text = "You can make Items selectable  by switching CheckBoxes property to True in the Properties windows and using CheckBox event handlers"
    End If
于 2017-09-02T20:33:01.930 回答