How to insert ComboBox item into ListBox? - in Visual Studio-- Windows Forms Application c#

How to insert ComboBox item into ListBox::This topic is designed to help you find code that demonstrates how to perform common ListBox and ComboBox and common button  in  programming tasks by using Visual C# Express Edition.

How to: Add and Clear Items in a ListBox Control
Demonstrates how to add items to a ListBox control and then remove them.
How to: Determine the Selected Item in a ListBox Control
Demonstrates how to determine which item is selected in a ListBox control.




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

        private void button1_Click(object sender, EventArgs e)
        {
            comboBox1.Items.Add("Prem");
            comboBox1.Items.Add("Srinu");
            for (int i = 1; i <= 30; i++)
                comboBox1.Items.Add(i);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(comboBox1.SelectedItem.ToString()); 
        }

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

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


Comments