IT KNOWLEDGE

IT KNOWLEDGE
BC

Saturday, July 11, 2015

Add-Remove Item from Listbox(VB.NET)

This tutorial, I combine Add items to Listbox using Textbox and Remove items from Listbox using 3 options:

  1. Remove the item that we select in Listbox
  2. Remove all items
  3. Remove items using textbox
Application Design:
  1. Form
    • Text          : Add-Remove Item From Listbox
    • Name        : AddRemoveFromListbox
    • Font Size   : 12pt
  2. Textbox(2)
    1. Textbox1
      • Name        : TextboxAdd
      • Font Size   : 12pt
    2. Textbox2
      • Name        : TextboxRemove
      • Font Size   : 12pt
  3. Button(2)
    1. ButtonAdd
      • Name        : ButtonAdd
      • Font Size   : 12pt
      • Text           : Add
    2. ButtonRemove
      • Name        : ButtonRemove
      • Font Size   : 12pt
      • Text           : Remove
  4. Groupbox
    • Text    :  GroupBoxOption
    • Name  :  Remove Option
  5. RadioButton(3)
    1. RadioButton1
      • Text: Select Item
      • Name: RadioSelectItem
    2. RadioButton2
      • Text: All
      • Name : RadioRemoveAll
    3. RadioButton3
      • Text : Select Index
      • Name : RadioSelectIndex
  6. Label
    • Name: LabelShow


Coding

Public Class AddRemoveFromListbox

    Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
        ListBoxData.Items.Add(TextBoxAdd.Text)
        TextBoxAdd.Clear()
        TextBoxAdd.Focus()
    End Sub

    Private Sub RadioSelectItem_CheckedChanged(sender As Object, e As EventArgs) Handles RadioSelectItem.CheckedChanged, RadioRemoveAll.CheckedChanged, RadioSelectIndex.CheckedChanged
        If RadioSelectItem.Checked = True Then
            LabelShow.Text = "This will be delete selected item that you select in Listbox!"
            TextBoxRemove.Visible = False
        ElseIf RadioRemoveAll.Checked = True Then
            LabelShow.Text = "This will delete all items in Listbox!"
            TextBoxRemove.Visible = False
        Else
            LabelShow.Text = "This will delete item that same text in TextboxRemove!"
            TextBoxRemove.Visible = True
        End If
    End Sub

    Private Sub ButtonRemove_Click(sender As Object, e As EventArgs) Handles ButtonRemove.Click
        If RadioSelectItem.Checked = True Then
            ListBoxData.Items.Remove(ListBoxData.SelectedItem)
        ElseIf RadioRemoveAll.Checked = True Then
            ListBoxData.Items.Clear()
        Else
            ListBoxData.Items.Remove(TextBoxRemove.Text)
        End If
    End Sub
End Class


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: itech-9999

0 comments: