Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 如何从一个组合框向另一个组合框添加值_Winforms_Visual Studio 2012 - Fatal编程技术网

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);
            }
        }
    }