Hi,
i have two listboxes(with Multi select option) in my form.
i want to add selected list items from firstlist box into second list box.
i wnt to restrict to add duplicate items.
plase advice.
thanks in advance.
Regards,
Balu Reddy
Loading
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.
Satyapriya NayakPosted Dec 4, 2011, 5:53 AM
Another way...
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();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Raj");
listBox1.Items.Add("Raj");
listBox1.Items.Add("Raju");
listBox1.Items.Add("Rahul");
listBox1.Items.Add("Harry");
listBox1.Items.Add("Ben");
listBox1.Items.Add("Ian");
}
private void btn_right_Click(object sender, EventArgs e)
{
if (listBox2.Items.Contains(listBox1.SelectedItem) == true)
{
MessageBox.Show("Item Exits");
}
else
{
listBox2.Items.Add(listBox1.SelectedItem);
int i = 0;
i = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(i);
}
}
private void btnleft_Click(object sender, EventArgs e)
{
listBox1.Items.Add(listBox2.SelectedItem);
int i = 0;
i = listBox2.SelectedIndex;
listBox2.Items.RemoveAt(i);
}
}
}
Thanks
If this post helps you mark it as answer
Prabhu RajaPosted Dec 3, 2011, 2:43 PM
satyapriya gives code for desktop application. if you need code sample for web application, then visit this link.
http://www.developergeekresources.com/examples/javascript/javascript-listbox_to_listbox.php
Satyapriya NayakPosted Dec 3, 2011, 7:38 AM
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;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
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 Form1_Load(object sender, EventArgs e)
{
List
input.Add("Raj");
input.Add("Ravi");
input.Add("Raju");
input.Add("Rahul");
input.Add("Raj");
input.Add("Ravi");
input.Add("Rahul");
List
foreach (string s in result)
{
listBox1.Items.Add(s);
}
}
private static List
{
Dictionary
foreach (string s in input)
tmp[s] = 1;
return new List
}
}
}
Thanks
Mayur GujrathiPosted Dec 3, 2011, 5:15 AM
Vikas MishraPosted Dec 3, 2011, 4:55 AM
For the above problem yuo should follow the following link........
http://www.java2s.com/Code/VB/GUI/Addremoveandclearlistboxitems.htm
Thanks..........