Winforms 如何从一个组合框向另一个组合框添加值
我有一个带有一些值列表的组合框。从列表中选择后,我需要将组合框中的其余值添加到另一个组合框中 如果我理解正确,此代码将帮助您Winforms 如何从一个组合框向另一个组合框添加值,winforms,visual-studio-2012,Winforms,Visual Studio 2012,我有一个带有一些值列表的组合框。从列表中选择后,我需要将组合框中的其余值添加到另一个组合框中 如果我理解正确,此代码将帮助您 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //If you need, clear second combo box from old values before you copy //comboBox2.Items.Clea
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//If you need, clear second combo box from old values before you copy
//comboBox2.Items.Clear();
foreach (var item in comboBox1.Items)
{
if (item != comboBox1.SelectedItem)
{
comboBox2.Items.Add(item);
//If you need to remove item that were copied to second combo box, from the first
//comboBox1.Items.Remove(item);
}
}
}