deleting rows from a listview

726 views
Skip to first unread message

Shawn

unread,
Mar 4, 2009, 5:06:36 PM3/4/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I would like to delete a complete row froma listview by selecting a
row and pressing delete, not a delete "button" but the actual delete
key. Is this possible or am I just missing something?

Benj Nunez

unread,
Mar 4, 2009, 8:44:21 PM3/4/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Yes. It is possible.

1) On your form, just drag a Listview.
2) In the Listview's Items property, add your strings (put 3 strings
for example).
3) Set the Listview's MultiSelect property to False.
4) In your Listview's KeyDown event, type:

private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
listView1.Items.Remove(listView1.FocusedItem);
}
}

5) Run the program. There's at least one item selected. Keep pressing
the 'Del' (Delete) key and watch
what will happen.



Cheers!


Benj

Shawn

unread,
Mar 6, 2009, 5:04:34 PM3/6/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Thank you, works perfectly. Knew I was missing something
Reply all
Reply to author
Forward
0 new messages