Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

How to delete a listview row

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

Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

lvNotes.Items.Remove(lvNotes.SelectedItems[0]);

Hope that helps.
ASKER CERTIFIED SOLUTION
Avatar of rgn2121
rgn2121
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial