locked
A Listbox problem RRS feed

  • Question

  • To all you experts out there,

    * I have a Listbox, that has been loaded correctly from a file.

    * I select a row by clicking on it. The content is shown correctly divided up in a few textboxes.

    * A Commandbutton becomes available.

    * When I click on it, Me.LstBxBarn.Items.Remove(ValtIndex) is executed. I have checked that "ValtIndex) is the index in the Listbox that I want to be removed.

    * But the row remains in the Listbox as I see it. I have tried to add a line Me.LstBxBarn.Refresh but that does`nt help.

    I`m very thankful for any help. I use VB 2010 Express.

    Kurt


    KB

    Tuesday, July 30, 2013 11:45 AM

Answers

  • Here is an example of using Listbox.Items.Remove() and ListBox.Items.RemoveAt().

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If ListBox1.SelectedItems.Count > 0 Then
                ListBox1.Items.Remove(ListBox1.SelectedItem) 'Remove removes an Item
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If ListBox1.SelectedIndices.Count > 0 Then
                ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) 'RemoveAt removes an item at an index
            End If
        End Sub
    

    Tuesday, July 30, 2013 12:49 PM