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 7769211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:06:10+00:00 2026-06-01T16:06:10+00:00

I have a checked list box and I’m writing code for two buttons, 1

  • 0

I have a checked list box and I’m writing code for two buttons, 1 that moves all selected items upward, and one that moves each item downward. The one for moving up works, but I cant get the other one to work:

//Move up
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < checkedListBox1.Items.Count; i++ ) {
                if (checkedListBox1.GetItemChecked(i)) {
                    checkedListBox1.Items.Insert(i - 1, checkedListBox1.Items[i]);
                    checkedListBox1.SetItemChecked(i - 1, true);
                    checkedListBox1.Items.RemoveAt(i + 1);
                }
            }
        }
//Move Down
        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = checkedListBox1.Items.Count - 2; i >= 0; i--)
            {
                if (checkedListBox1.GetItemChecked(i))
                {
                    checkedListBox1.Items.Insert(i + 1, checkedListBox1.Items[i]);
                    checkedListBox1.SetItemChecked(i + 1, true);
                    checkedListBox1.Items.RemoveAt(i);
                }
            }
        }
  • 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-06-01T16:06:11+00:00Added an answer on June 1, 2026 at 4:06 pm

    I think you need this in the second method:

    checkedListBox1.Items.Insert(i + 2, checkedListBox1.Items[i]);
    checkedListBox1.SetItemChecked(i + 2, true);
    

    You’re current method is inserting a copy of the current element before the following element, which bascially just puts it in the same location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to do some actions when all items in checked list box are
I have a list box and i am trying to get currently checked item
hello friends i have a check box list which contains all the courses kept
I have a list of items that have checkboxes associated with them, and the
I have this Checked List Box, listPlayers . I would like to have it
Hi I have made checked List Box in WPF but the binding is not
If I have Checked list box in Win forms which I fill like this
I have javascript validation that validates items such as textboxes, radio buttons etc. How
i am using asp.net c# jquery vs 2008 I have two check box list
I have a JavaScript function that goes through a list of checked checkboxes and

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.