Move items from one listbox to another C# Form Application
Do this for me I need your help friends.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mitesh PatelPosted Dec 26, 2014, 9:00 PM
Jyotsna AggrawalPosted Dec 26, 2014, 5:29 AM
Move Items from one ListBox to another in CSharp .NET
Satyapriya NayakPosted Jun 13, 2013, 10:11 AM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Move_items_from_one_listbox_other
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Raj");
listBox1.Items.Add("Ravi");
listBox1.Items.Add("Rahul");
listBox1.Items.Add("Raju");
listBox1.Items.Add("Rohit");
listBox1.Items.Add("Rajesh");
}
private void button1_Click(object sender, EventArgs e)
{
listBox2.Items.Add(listBox1.SelectedItem);
int i = 0;
i = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(i);
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(listBox2.SelectedItem);
int i = 0;
i = listBox2.SelectedIndex;
listBox2.Items.RemoveAt(i);
}
private void button3_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= listBox1.Items.Count - 1; j++)
{
listBox2.Items.Add(listBox1.Items[j]);
}
listBox1.Items.Clear();
}
private void button4_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= listBox2.Items.Count - 1; j++)
{
listBox1.Items.Add(listBox2.Items[j]);
}
listBox2.Items.Clear();
}
}
}
Pankaj PandeyPosted Jun 13, 2013, 9:16 AM
Pankaj PandeyPosted Jun 13, 2013, 9:06 AM
clear one thing, are you want to move or add to other listbox??
In move, it delete from first and add to 2nd and copy for already remain in first and add to 2nd ??
tell me, i'll give you code