Hi
Please find the code for your first question
ADD Two listboxes named lstSource and lstDest
ADD Two Buttons named btnAdd and btnRemove in a windows form.
///////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// I am loading my list box with some sample data.
lstSource.Items.Add("Item1");
lstSource.Items.Add("Item2");
lstSource.Items.Add("Item3");
lstSource.Items.Add("Item4");
lstSource.Items.Add("Item5");
//Set these if you want to move multiple items across list boxes.
//Source List Box Name : lstSource
lstSource.SelectionMode = SelectionMode.MultiExtended;
//Destination List Box Name : lstDest
lstDest.SelectionMode = SelectionMode.MultiExtended;
}
private void btnAdd_Click(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection obcol = lstSource.SelectedItems;
List<object> objlist = new List<object>();
foreach (var item in obcol)
{
lstDest.Items.Add(item);
objlist.Add(item);
}
foreach (var item in objlist)
{
lstSource.Items.Remove(item);
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection obcol = lstDest.SelectedItems;
List<object> objlist = new List<object>();
foreach (var item in obcol)
{
lstSource.Items.Add(item);
objlist.Add(item);
}
foreach (var item in objlist)
{
lstDest.Items.Remove(item);
}
}
}
}
Madhavi, if this helps please login to Mark As Answer. | Alert Moderator