0

how can I use Alt+Del to Delete listview item ...
Now I just select the row and press del key delete the item, But I want to delete item by press alt+del key. How it is possible Please help me....

What I have tried:

 Private Sub ListView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListView1.KeyDown

            If e.KeyCode = Keys.Delete Then

                Dim i As ListViewItem
                i = ListView1.SelectedItems(0)
                i.Remove()

            End If

        End Sub
3
Contributors
8
Replies
42
Views
1 Month
Discussion Span
Last Post by xrj
0

Are you talking about a ListView, a container of images? Or perhaps are you refering to a listbox filled with items?

Edited by xrj

0

Dim i As ListViewItem

  i = ListView1.Items.Add(txtitemsl.Text)
        i.SubItems.Add(cmbitemNM.Text)
        i.SubItems.Add(txtitmnm.Text)
        i.SubItems.Add(txtitmdes.Text)
        i.SubItems.Add(txtitemqty.Text)
        i.SubItems.Add(txtitemmrp.Text)
        i.SubItems.Add(txtitemrate.Text)
        i.SubItems.Add(txtitemdis.Text)
        i.SubItems.Add(txtitemvat.Text)
        i.SubItems.Add(txtitemtaxamt.Text)
        i.SubItems.Add(txtnettax.Text)
        i.SubItems.Add(txtitemamt.Text)
Attachments Capture.PNG 25.17 KB
0

I would code this way:

    Public Sub listView1_KeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles ListView1.KeyDown
        If e.Key = Key.System AndAlso _
        e.SystemKey = Key.Delete Then
            If ListView1.SelectedItems.Count Then
                Dim item As ListViewItem = ListView1.SelectedItems(0)
                ListView1.Items.Remove(item)
                e.Handled = True
            End If
        End If
    End Sub
0

Please post that code as of the start of the Sub to the end of that sub End Sub so that we can see what's wrong, but I think your code is outside the Sub that why you are getting those errors but that can be confirmed after you have posted the code as I stated above so that we can see what went wrong or what is wrong with your code.

1

Sorry, I thought your code was for WPF. So, it should be:

    Public Sub listView1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ListView1.KeyDown
        If e.Modifiers = Keys.Alt AndAlso _
        e.KeyCode = Keys.Delete Then
            If ListView1.SelectedItems.Count Then
                Dim item As ListViewItem = ListView1.SelectedItems(0)
                ListView1.Items.Remove(item)
                e.Handled = True
            End If
        End If
    End Sub
0

Hay!
Thanks, many many thanks. It is work fine thank you
You are Great.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.