Hie
Help me do it
I want to use button's (i am willing to use 4 buttons i.e > , >> , < , << ) as an interface and want to perform items transfer between list boxes vice verse without duplication .
Once check the attachment . attached image :)
Thank you
Loading

Satyapriya NayakPosted Feb 11, 2013, 12:03 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();
}
}
}
Thanks
If this post helps you mark it as answer
SUNIL GUTTAPosted Feb 11, 2013, 1:37 PM
Thank you so so much for reply & helping me out :) very grateful to you
Well in ur solution that is near perfect but you used FOR loop for all four button_event_proc which is not efficient as it can't handle Nulll values :)
so please replace your code of button 3 & 4 with this type using foreach loop
Button3_event_proc
Button4_evnt_proc
foreach (object item in listBox2.Items)
Thank you for reply once again
Hey but still exceptions are getting due to no i/p selected i am working n for loops of 1&2 buttons for possible replacement with foreach again :) if possible so then solution will be apt :)