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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:53:10+00:00 2026-05-13T17:53:10+00:00

Ok so I’m trying to move items from one listbox to another by using

  • 0

Ok so I’m trying to move items from one listbox to another by using multiple buttons i.e

I have 2 buttons cmdRight and cmdRight2 which are both disabled on form load

If the user selects a single item on the first listbox a cmdRIght button enables but cmdRight2 is still disabled , if the user selects multiple items on the first listbox a cmdRight2 button enables but cmdRight is disabled.

I’ve got the move buttons to work but the problem I’m having is after moving multiple items with the cmdRight2 button the cmdRight button enables (which it shouldn’t it should only enable after selecting a single item in the listbox). I’ve tried numerous if statements etc. and yet it still happens.

I’m new to C# so any help would be appreciated.

Thank You

        private void lbList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.lbList1.SelectedItems != null)
            {
                cmdRight.Enabled = true; //enable cmdRight
                cmdClear.Enabled = true; //enable cmdClear
                if (this.lbList1.SelectedItems.Count > 1)//if multiple items selected
                {
                    cmdRight.Enabled = false;
                    cmdRight2.Enabled = true; //enable cmdRight2              
                }
            }
        }


    private void cmdRight2_Click(object sender, EventArgs e)
    {
        foreach (int i in lbList1.SelectedIndices)
        {
            lbList2.Items.Add(lbList1.Items[i].ToString());
        }
        while (lbList1.SelectedItems.Count > 0)
        {
            lbList1.Items.Remove(lbList1.SelectedItems[0]);
        }
        cmdRight2.Enabled = false;

    }

    private void cmdRight_Click(object sender, EventArgs e)
    {
        lbList2.Items.Add(lbList1.SelectedItem); //Add selected item from list1 to list2
        lbList1.Items.Remove(lbList1.SelectedItem);//remove the selected item in list1

        cmdRight.Enabled = false; //disable cmdRight
    }
  • 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-13T17:53:11+00:00Added an answer on May 13, 2026 at 5:53 pm

    I think you want

    if (this.lbList1.SelectedItems.Count == 1)
    {
    }
    else if(this.lbList1.SelectedItems.Count > 1)
    {
    }
    else
    {
    }
    

    instead of

    if (this.lbList1.SelectedItems != null)
    

    Then you could place all of this in a method called “EnableButtons” as mentioned elsewhere

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

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In a java program you can't change the running location.… May 14, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer You really don't want to parse HTML using RegEx. See… May 14, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer use css : p { margin:0 } Try this wonderful… May 14, 2026 at 4:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.