---
title: "Move Items from one ListBox to Another in CSharp .NET"  
description: "To move items from ListBox1 to ListBox2 and  vice-versa, we would have to write code for four buttons.·         Forward: to move selected item in list"  
author: "Anonymous User"  
published: 2010-07-16  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/84/move-items-from-one-listbox-to-another-in-csharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Move Items from one ListBox to Another in CSharp .NET

##### ![Move Items from one ListBox to Another in CSharp .NET](https://www.mindstick.com/mindstickarticle/5d02d2bc-82f8-4543-8780-f03a37b5f0aa/images/308bdf33-287d-46a8-8af0-c44a41e23134.png)

##### To move items from ListBox1 to ListBox2 and vice-versa, we would have to write code for four buttons.

· Forward: to move selected item in listbox1 to listbox2.

· Forward All: to move all items from listbox1 to listbox2

· Remove: to remove item from listbox2 and add in listbox1

· Remove All: to remove all items in listbox2 and add in listbox1

##### Forward

![Move Items from one ListBox to Another in CSharp .NET](https://www.mindstick.com/mindstickarticle/5d02d2bc-82f8-4543-8780-f03a37b5f0aa/images/bc0a3626-5b93-4b8d-bc0a-5467321e11d3.png)

```
private void btnforward_Click(object sender, EventArgs e)        {            try            {                if (listBox1.Items.Count > 0)                {// checking whether listbix1 has items or not if yes then moving items                    listBox2.Items.Add(listBox1.SelectedItem.ToString());                    listBox1.Items.Remove(listBox1.SelectedItem);                }                           }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }//selecting first item of listbox.            if(listBox1.Items.Count>0)                listBox1.SelectedIndex = 0;            listBox2.SelectedIndex = listBox2.Items.Count - 1;        }
```

##### Forward All

![Move Items from one ListBox to Another in CSharp .NET](https://www.mindstick.com/mindstickarticle/5d02d2bc-82f8-4543-8780-f03a37b5f0aa/images/6abd1e10-de31-462e-9e86-35337fb6146a.png)

```
        private void btnForwardAll_Click(object sender, EventArgs e)        {            try            {   //moving all items from listbox1 to listbox2                listBox2.Items.AddRange(listBox1.Items);                listBox1.Items.Clear();            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }            listBox2.SelectedIndex = 0;        }
```

##### Remove

![Move Items from one ListBox to Another in CSharp .NET](https://www.mindstick.com/mindstickarticle/5d02d2bc-82f8-4543-8780-f03a37b5f0aa/images/42eff1fc-36f7-4f3d-b669-989cbea004e5.png)

```
        private void btnRemove_Click(object sender, EventArgs e)        {            try            {                if (listBox2.Items.Count > 0)                {                  //checking whether listbox2 has items or not. If yes then moving                     //selected item from listbox2 to listbox1                    listBox1.Items.Add(listBox2.SelectedItem.ToString());                    listBox2.Items.Remove(listBox2.SelectedItem);                }            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }            if (listBox2.Items.Count > 0)                listBox2.SelectedIndex = 0;            listBox1.SelectedIndex = listBox1.Items.Count - 1;         }
```

##### Remove All

![Move Items from one ListBox to Another in CSharp .NET](https://www.mindstick.com/mindstickarticle/5d02d2bc-82f8-4543-8780-f03a37b5f0aa/images/b4a20da0-6a2f-4274-afa4-1be66b43123a.png)

```
        private void btnRemoveAll_Click(object sender, EventArgs e)        {            try            {               //moving all items from listbox2 to listbox1                listBox1.Items.AddRange(listBox2.Items);                listBox2.Items.Clear();            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }             listBox1.SelectedIndex = 0;         }
```

---

Original Source: https://www.mindstick.com/articles/84/move-items-from-one-listbox-to-another-in-csharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
