Remove an Item from a ListBox

0

I need to delete an item from a ListBox , but I have two forms, in the first one is ListBox and in the second one too, but I need that when I press the delete button the first items that came in as I can be deleted do?

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    Form2.ListBox1.Items.RemoveAt(Form2.ListBox1.SelectedIndex)
End Sub
    
asked by WilsonicX 15.03.2018 в 16:40
source

2 answers

1

To eliminate the last item that was sent to listbox, the following code must be executed:

   Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1)
    Form2.ListBox1.Items.RemoveAt(Form2.ListBox1.Items.Count - 1)
End Sub
    
answered by 15.03.2018 / 16:52
source
1

If the Items are in the same positions, it is done like this:

Private Sub Button4_Click (sender As Object, and As EventArgs) Handles Button4.Click     ListBox1.Items.RemoveAt (ListBox1.SelectedIndex)     Form2.ListBox1.Items.RemoveAt (ListBox1.SelectedIndex) End Sub

If it is not so that the elements are disordered you should make a new function with which to eliminate that element, but always part of the element that was eliminated in the first list, therefore the first SelectedIndex is used since the second is not selected ...

    
answered by 23.06.2018 в 13:00