How do I get the value of the selected item in the listbox? [duplicate]

1

This way I did I could not, from Object reference not set to an instance of an object!

Private Sub btnDeletarPerfil_Click(sender As Object, e As EventArgs) Handles btnDeletarPerfil.Click

    Roles.DeleteRole(lbPerfis.SelectedItem.Value.ToString())

ou dessa maneira >>
    Roles.DeleteRole(lbPerfis.SelectedItem.Text.ToString())

End Sub
    
asked by anonymous 09.06.2015 / 04:52

1 answer

1

In case the item is selected, correct and it is this item that you want to exclude from the listbox.

So in this case it is more interesting to use the listbox index to delete

Private Sub btnDeletarPerfil_Click(sender As Object, e As EventArgs) Handles btnDeletarPerfil.Click

    lbPerfis.Items.RemoveAt(lbPerfis.SelectedItem.SelectedIndex)


End Sub
    
09.06.2015 / 15:45