簡體   English   中英

如何在列表框或列表視圖中添加組合框項目

[英]how to add combobox items in listbox or listview

我想知道要在我的項目上使用的控件是Listview還是listbox ???。 我在項目上有一個comboBox控件,我要做的是,當我在組合框上選擇1個項目時,它將自動添加到列表框或listview上,而當我選擇多個項目時,我想將其添加到換行上的listbox或listview上。 ..

簡單嗎,請幫助我在列表框或列表視圖中執行此操作。謝謝!

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

如果您的項目希望從組合框選擇的列表中查看列表,則只需選擇“列表視圖”,但是如果您也想查看,則用戶可以選擇它,更好地使用列表框,由您決定。 您也可以通過將鼠標光標放在該工具上來了解“工具”的工作方式,然后它將彈出一個工具提示,其中寫有該工具的用途。

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

那就是要在列表視圖中查看在組合框中選擇的代碼

要清除Listview或listbox中的所有項目,只需寫入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

可以通過以下兩種方式選擇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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM