This tutorial, I combine Add items to Listbox using Textbox and Remove items from Listbox using 3 options:
- Remove the item that we select in Listbox
- Remove all items
- Remove items using textbox
Application Design:
- Form
- Text : Add-Remove Item From Listbox
- Name : AddRemoveFromListbox
- Font Size : 12pt
- Textbox(2)
- Textbox1
- Name : TextboxAdd
- Font Size : 12pt
- Textbox2
- Name : TextboxRemove
- Font Size : 12pt
- Button(2)
- ButtonAdd
- Name : ButtonAdd
- Font Size : 12pt
- Text : Add
- ButtonRemove
- Name : ButtonRemove
- Font Size : 12pt
- Text : Remove
- Groupbox
- Text : GroupBoxOption
- Name : Remove Option
- RadioButton(3)
- RadioButton1
- Text: Select Item
- Name: RadioSelectItem
- RadioButton2
- Text: All
- Name : RadioRemoveAll
- RadioButton3
- Text : Select Index
- Name : RadioSelectIndex
- 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
0 comments:
Post a Comment