Design form having textbox and 2 listbox Accept item from textbox and add into IistboxI.
Transfer item from list! to Iist2 and reverse.
ok above question is already answered to link below till accept item... but i just wanted to know what if we want to transfer item from list! to list 2 and ... from list2 to list! ?? so i added it again with link, so all guys can see it...
http://www.c-sharpcorner.com/Forums/Thread/205790/design-form-having-textbox-and-2-listbox-and.aspx
Loading
VulpesPosted Apr 7, 2013, 7:13 PM
and to transfer back to list1:
xenoix babaPosted Apr 8, 2013, 12:21 PM
xenoix babaPosted Apr 8, 2013, 12:21 PM
Satyapriya NayakPosted Apr 7, 2013, 11:48 PM
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();
}
}
}