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

  • Home
  • SEARCH
  • 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 6367821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:35:54+00:00 2026-05-25T00:35:54+00:00

I am trying to achieve some thing one these lines ,I have two listboxes

  • 0

I am trying to achieve some thing one these lines ,I have two listboxes listbox1 and listbox2 ,i have the add and delete button respectively to move the items from one listbox to another.For some reason i am unable to select the item from the list box after couple of moves .

I am using the following code

logic for Add button

ArrayList listitems1 = new ArrayList();
        ArrayList listitems2 = new ArrayList();
        if (listBox2.SelectedItem == null)
        {
            System.Windows.MessageBox.Show("*Please Select unassigned Wks ");
            return;
        }
        else
        {
            try
            {
                foreach (string st in listBox2.Items)
                {
                    listitems1.Add(st);
                }

                foreach (string st1 in listBox1.Items)
                {
                    listitems2.Add(st1);
                }
                if (listBox2.SelectedIndex > -1)
                {
                    string value = listBox2.SelectedItem.ToString();
                    string text = listBox2.SelectedItem.ToString();
                    listitems2.Add(value);
                    listBox1.ItemsSource = listitems2;
                    listitems1.Remove(value);
                    listBox2.ItemsSource = listitems1;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }



      **logic for delete button:**

        ArrayList listitems1 = new ArrayList();
        ArrayList listitems2 = new ArrayList();
        if (listBox2.SelectedItem == null)
        {
            System.Windows.MessageBox.Show("*Please Select unassigned Wks ");
            return;
        }
        else
        {
            try
            {
                foreach (string st in listBox2.Items)
                {
                    listitems1.Add(st);
                }

                foreach (string st1 in listBox1.Items)
                {
                    listitems2.Add(st1);
                }
                if (listBox2.SelectedIndex > -1)
                {
                    string value = listBox2.SelectedItem.ToString();
                    string text = listBox2.SelectedItem.ToString();
                    listitems2.Add(value);
                    listBox1.ItemsSource = listitems2;
                    listitems1.Remove(value);
                    listBox2.ItemsSource = listitems1;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        ArrayList listitems1 = new ArrayList();
        ArrayList listitems2 = new ArrayList();
        try
        {
            foreach (string st in listBox2.Items)
            {
                listitems1.Add(st);
            }

            foreach (string st1 in listBox1.Items)
            {
                listitems2.Add(st1);
            }
            if (listBox1.SelectedIndex > -1)
            {
                string value = listBox1.SelectedItem.ToString();
                string text = listBox1.SelectedItem.ToString();
                listitems1.Add(value);
                listBox2.ItemsSource = listitems1;
                listitems2.Remove(value);
                listBox1.ItemsSource = listitems2;

            }
        }
  • 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-25T00:35:54+00:00Added an answer on May 25, 2026 at 12:35 am

    Try this. For your add method:

    if (listBox2.SelectedItem == null)
    {
        System.Windows.MessageBox.Show("*Please Select unassigned Wks ");
        return;
    }
    else
    {
        if (listBox2.SelectedIndex > -1)
        {
            Object obj = listBox2.SelectedItem;
            listBox1.Items.Add(obj);
            listBox2.Items.Remove(obj);
        }
    }
    

    Do something similar for the delete method. I think the problem might be that you are using ArrayLists as the source for the ListBox items, and the ArrayLists go out of scope.

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

Sidebar

Related Questions

I am trying to add some styles in some DataGrid s I have. I
I'm trying to write a project that will have some autonomous components. One of
how can i paste something on multiple lines? i'm trying to achieve the same
I would really appreciate some feedback on what I am trying to achieve: The
What I am trying to achieve is a form that has a button on
I'm trying to achieve something along the lines of... UserControl (MyRepeater) <p>Control Start</p> <asp:Repeater
What I have to do I'm trying to manipulate some rather large amounts of
Here's what I'm trying to achieve. I have a directory with over 4200 sub-files/sub-directories,
I've trying to achieve something like this: class Base { public: Base(string S) {
I'm trying to achieve something google isn't able to give answer. I'm trying to

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.