「VB.NET」リストボックス(ListBox)のアイテムを削除
1.指定項目を削除
書式
ListBox名.Items.Remove(“項目名”)
使用例
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim count As Integer ListBox1.Items.Remove("B002") '項目数を取得 count = ListBox1.Items.Count TextBox1.Text = "項目数: " + count.ToString End Sub
2.指定位置の項目を削除
書式
ListBox名.Items.RemoveAt(削除位置)
使用例
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim count As Integer ListBox1.Items.RemoveAt(2) '項目数を取得 count = ListBox1.Items.Count TextBox1.Text = "項目数: " + count.ToString End Sub
3.全てを削除
書式
ListBox名.Items.Clear()
使用例
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim count As Integer ListBox1.Items.Clear() '項目数を取得 count = ListBox1.Items.Count TextBox1.Text = "項目数: " + count.ToString End Sub