How to add items to list box and undo the added items

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 1388
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Listbox_add_undo_items
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btn_add_Click(object sender, EventArgs e)
{
listBox1.SelectedIndex = listBox1.Items.Add(textBox1.Text);
textBox1.Clear();
}

private void btn_undo_Click(object sender, EventArgs e)
{
if (listBox1.Items.Count > 0)
{
listBox1.Items.RemoveAt(listBox1.Items.Count - 1);
}
}
}
}

Comments or Responses

Login to post response