Add and Remove item in Visual Basic.Net Listbox

Download
Download is available until [expire_date]
  • Version
  • Download 71
  • File Size 297.98 KB
  • File Count 1
  • Create Date March 3, 2016
  • Last Updated March 3, 2016

Add and Remove item in Visual Basic.Net Listbox

Add and Remove item in Visual Basic.Net Listbox

PDF tutorial and source code on how to create a program in vb.net that allows you to add and remove item in a listbox control.

Sample code:

Public Class Form1
'code to add item
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MessageBox.Show("Please enter a text in textbox")
            TextBox1.Focus()
        Else
            ListBox1.Items.Add(TextBox1.Text)
            TextBox1.Clear()
        End If
    End Sub
'code to remove item
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ListBox1.SelectedItem = "" Then
            MessageBox.Show("please select item to remove")
        Else
            ListBox1.Items.Remove(ListBox1.SelectedItem)
        End If

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        MessageBox.Show("selected: " & ListBox1.SelectedItem.ToString)
    End Sub
End Class
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.