Remove items when selected in combobox

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 815
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 Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("One");
comboBox2.Items.Add("One");
comboBox1.Items.Add("Two");
comboBox2.Items.Add("Two");
comboBox1.Items.Add("Three");
comboBox2.Items.Add("Three");
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string value1 = comboBox1.Text;
string value2 = "";
for (int i = 0; i < comboBox2.Items.Count; i++)
{
value2 = comboBox2.Items[i].ToString();
if (value1 == value2)
{
comboBox2.Items.RemoveAt(i);
}
}
}
}
}

Comments or Responses

Login to post response