Solved

How to delete a listview row

Posted on 2011-09-16
2
345 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
ID: 36549427
lvNotes.Items.Remove(lvNotes.SelectedItems[0]);

Hope that helps.
0
 
LVL 12

Accepted Solution

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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