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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vikas MishraRank #559 · 4.3K reputationPosted Dec 2, 2011, 11:55 PM EST
For the above problem yuo should follow the following link........
http://www.java2s.com/Code/VB/GUI/Addremoveandclearlistboxitems.htm
Thanks..........
Mayur GujrathiRank #666 · 3.6K reputationPosted Dec 3, 2011, 12:15 AM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 3, 2011, 2:38 AM EST
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
Prabhu RajaRank #861 · 2.6K reputationPosted Dec 3, 2011, 9:43 AM EST
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 NayakRank #47 · 31.5K reputationPosted Dec 4, 2011, 12:53 AM EST
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