Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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
C# 删除过程中修改了Listbox项目集合;枚举操作不能执行_C#_Asp.net_C# 4.0 - Fatal编程技术网

C# 删除过程中修改了Listbox项目集合;枚举操作不能执行

C# 删除过程中修改了Listbox项目集合;枚举操作不能执行,c#,asp.net,c#-4.0,C#,Asp.net,C# 4.0,我必须将一个项目从一个列表框移动到另一个列表框,如上图所示 >按钮将一个或多个选定项从listbox1移动到listbox2 >>按钮将所有项目从listbox1移动到listbox2 您正在对集合进行迭代时对其进行修改。我没有IDE,但您可以尝试: protected void btn3_Click(object sender, EventArgs e) { lbltext.Visible = false; if (lstBoxAreaOfResponsibility2.It

我必须将一个项目从一个列表框移动到另一个列表框,如上图所示

  • >按钮将一个或多个选定项从listbox1移动到listbox2
  • >>按钮将所有项目从listbox1移动到listbox2

  • 您正在对集合进行迭代时对其进行修改。我没有IDE,但您可以尝试:

    protected void btn3_Click(object sender, EventArgs e)
    {
        lbltext.Visible = false;
        if (lstBoxAreaOfResponsibility2.Items.Count != 0)
        {
            lstBoxAreaOfResponsibility2.Items.Clear();
        }
        else
        {
            lbltext.Visible = true;
            lbltext.Text = "There Is No Item To Move";
        }
    }
    
    protected void btn4_Click(object sender, EventArgs e)
    {
        lbltext.Visible = false;
        if (lstBoxAreaOfResponsibility2.SelectedIndex >= 0)
        {
            ListItem itemToDelete = new ListItem();
            foreach (ListItem Item in lstBoxAreaOfResponsibility2.Items)
            {
                if (Item.Selected == true)
                {
                    itemToDelete = Item;
                }
            }
            lstBoxAreaOfResponsibility2.Items.Remove(itemToDelete);
        }
        else
        {
            lbltext.Visible = true;
            lbltext.Text = "Please select atleast one in Listbox2 to move";
        }
    }
    
    为了它的价值,有一个
    protected void btn3_Click(object sender, EventArgs e)
    {
        lbltext.Visible = false;
        if (lstBoxAreaOfResponsibility2.Items.Count != 0)
        {
            lstBoxAreaOfResponsibility2.Items.Clear();
        }
        else
        {
            lbltext.Visible = true;
            lbltext.Text = "There Is No Item To Move";
        }
    }
    
    protected void btn4_Click(object sender, EventArgs e)
    {
        lbltext.Visible = false;
        if (lstBoxAreaOfResponsibility2.SelectedIndex >= 0)
        {
            ListItem itemToDelete = new ListItem();
            foreach (ListItem Item in lstBoxAreaOfResponsibility2.Items)
            {
                if (Item.Selected == true)
                {
                    itemToDelete = Item;
                }
            }
            lstBoxAreaOfResponsibility2.Items.Remove(itemToDelete);
        }
        else
        {
            lbltext.Visible = true;
            lbltext.Text = "Please select atleast one in Listbox2 to move";
        }
    }