Add, Remove Item in C# Listbox Control

Download
Download is available until [expire_date]
  • Version
  • Download 53
  • File Size 329.90 KB
  • File Count 1
  • Create Date March 1, 2016
  • Last Updated March 1, 2016

Add, Remove Item in C# Listbox Control

Add, Remove Item in C# Listbox Control

This is a step by step tutorial in c# that will teach you on how to add and remove items in listbox
The file contains the source code of the program as well as the pdf tutorial.

Source code:

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("please enter a name");
                textBox1.Focus();
            }
            else
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text = "";
                textBox1.Focus();        
            }
        }

        void loadlist()
        {
            listBox1.Items.Add("John");
            listBox1.Items.Add("Mark");
            listBox1.Items.Add("Joe");
            listBox1.Items.Add("Philip");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            loadlist();
        }

        private void button2_Click(object sender, EventArgs e)
        {
   
                listBox1.Items.Remove(listBox1.SelectedItem);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }

       

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            MessageBox.Show("selected: " + listBox1.SelectedItem.ToString());
        }

        
    }
}
, , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.