How to get the value of the selected item in the listbox?

Asked

Viewed 1,622 times

1

That way I did I couldn’t, 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
  • A very silly doubt, but you are selected something in your lbPerfis?

  • Yes, I’m the field has validation!

1 answer

1

In case the item is selected, correct and it is this item that you want to delete from 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.