Wednesday, July 28, 2010

Program to implement all the functionalities of ListBox Control.


Write a program to implement all the functionalities of ListBox Control.


using System;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox1.Text);
        }

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

        private void button3_Click(object sender, EventArgs e)
        {
            listBox1.Items.RemoveAt(Convert.ToInt32(textBox2.Text));
        }

        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Insert(Convert.ToInt32(textBox2.Text), textBox1.Text);
        }


        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            label1.Text = "";
            foreach (string s in listBox1.SelectedItems)
            {
                if (!label1.Text.Contains(s))
                {
                    label1.Text = label1.Text + "     " + s;
                }
            }
           

        }

        private void button5_Click(object sender, EventArgs e)
        {
            listBox2.Items.Add(listBox1.SelectedItem);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            int i = listBox1.SelectedIndex;
            listBox2.Items[i] = listBox1.SelectedItem;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(listBox2.SelectedItem);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            int i = listBox2.SelectedIndex;
            listBox1.Items[i] = listBox2.SelectedItem;
        }
    }
}

No comments:

Post a Comment