Solved

How to delete a listview row

Posted on 2011-09-16
2
342 Views
Last Modified: 2013-12-17
Hi,

I have a listview on my form with 2 toolbar-buttons. One button is for adding a row
to the listview. And I would like the second button for deleting a row that the user
has selected.

Does anyone know the code for deleting a row in a listview that is selected by a user?

 

Greetings,
Peter
Code for adding a row to the listview:

private void tbNewNote_Click(object sender, EventArgs e)
{
frmNote.txtCaption.Text = "";
frmNote.rtbContent.Clear();
frmNote.lblCreation.Text = (DateTime.Now.ToString());
if (frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ListViewItem myItem = new ListViewItem(frmNote.txtCaption.Text, 0);
myItem = lvNotes.Items.Add(myItem);
myItem.SubItems.Add(frmNote.rtbContent.Text);
myItem.SubItems.Add(frmNote.lblCreation.Text);
}
}

Open in new window

0
Comment
Question by:peterkiers
2 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
Comment Utility
lvNotes.Items.Remove(lvNotes.SelectedItems[0]);

Hope that helps.
0
 
LVL 12

Accepted Solution

by:
rgn2121 earned 500 total points
Comment Utility
foreach (ListViewItem item in ListView1.SelectedItems) {
      ListView1.Items.Remove(item);
}
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now