Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:01:07+00:00 2026-05-31T00:01:07+00:00

My windows form contains two listboxes. Listbox1 contains some items in it and listbox2

  • 0

My windows form contains two listboxes. Listbox1 contains some items in it and listbox2 is empty. When I press a button on the form, then multiple selected items from listbox1 should be removed from Listbox1 and copied to Listbox2.

I tried with foreach loop on listbox1.SelectedItems but it removes only 1 item from list.

Anyone has solution or code for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:01:09+00:00Added an answer on May 31, 2026 at 12:01 am

    You could do all in a single loop. You should use a simple for and loop backwards on SelectedIndices:

    private void button1_Click(object sender, EventArgs e) 
    { 
        for(int x = listBox1.SelectedIndices.Count - 1; x>= 0; x--)
        { 
            int idx = listBox1.SelectedIndices[x];
            listBox2.Items.Add(listBox1.Items[idx]); 
            listBox1.Items.RemoveAt(idx);
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a(n) (MDI) Windows Form application. It contains two forms. One form (Measured
My windows Form contains 1 combobox bound to Categories bindingsource, and 1 datagrid bound
i have a windows form that contains a bunch of textboxes. I need a
I have a C# Windows Form application that contains a menu with this event:
I've a windows .Net Form which contains a WebBrowser Control. This WebBrowser displays a
I have a form MainForm which is a Windows Forms form that contains many
I have a jQuery Model windows which contains a form. On creating of the
Windows form application(.Net 3.5) I have a textbox and a button on the form.
I have a form with three panels. The top panel contains listboxes, the middle
In a Windows Form application I have a Form with a UserControl that contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.