Write a program to transfer an item from First Listbox to Second Listbox and from Second Listbox to First.
Design:-
Code:-
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 List_Items_Mover
{
public partial class frmlistiemsmover : Form
{
public frmlistiemsmover()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void btnright_Click(object sender, EventArgs e)
{
listBox2.Items.Add(listBox1.SelectedItem);
int i = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(i);
}
private void btnleft_Click(object sender, EventArgs e)
{
listBox1.Items.Add(listBox2.SelectedItem);
int i = listBox2.SelectedIndex;
listBox2.Items.RemoveAt(i);
}
private void btnselectedright_Click(object sender, EventArgs e)
{
foreach(var item in listBox1.SelectedItems)
{
listBox2.Items.Add(item);
}
for (int i = listBox1.SelectedItems.Count - 1; i >= 0; i--)
{
listBox1.Items.Remove(listBox1.SelectedItems[i]);
}
}
private void btnselectedleft_Click(object sender, EventArgs e)
{
foreach (var items in listBox2.SelectedItems)
{
listBox1.Items.Add(items);
}
for (int i = listBox2.SelectedItems.Count - 1; i >= 0; i--)
{
listBox2.Items.Remove(listBox2.SelectedItems[i]);
}
}
private void btnallright_Click(object sender, EventArgs e)
{
if (listBox1.Items.Count != 0)
{
for (int i = 0; i <= listBox1.Items.Count - 1; i++)
{
listBox2.Items.Add(listBox1.Items[i]);
}
listBox1.Items.Clear();
}
else
{
MessageBox.Show("ListBox 1 Is Empty", "List Items Mover");
}
}
private void btnallleft_Click(object sender, EventArgs e)
{
if (listBox2.Items.Count != 0)
{
for (int i = 0; i <= listBox2.Items.Count - 1; i++)
{
listBox1.Items.Add(listBox2.Items[i]);
}
listBox2.Items.Clear();
}
else
{
MessageBox.Show("ListBox 2 is Empty", "List Items Mover");
}
}
private void btnexit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
No comments:
Post a Comment