Results 1 to 3 of 3

Thread: Delete ListBox Item Via Delete Key

  1. #1

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Delete ListBox Item Via Delete Key

    How would I make it so that if I select an item in ListBox1 and I press the "Delete" key then it will be removed?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Delete ListBox Item Via Delete Key

    You'd handle the key down event, and delete the selected item.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: Delete ListBox Item Via Delete Key

    Came up with this,

    Code:
        Private Sub ListBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
            If e.KeyCode = Keys.Delete AndAlso ListBox1.SelectedItem <> Nothing Then
                ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
            End If
        End Sub
    Sorry for not trying anything before asking a question.

    I think since I have access to getting a quick answer I should ask before experimenting by myself... I really need to stop doing that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width