using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DragDrop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem == )
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Orange");
listBox1.Items.Add("Pineapple");
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
listBox1.DoDragDrop(listBox1.SelectedItem, DragDropEffects.Move);
}
private void listBox2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Move;
}
}
private void listBox2_DragDrop(object sender, DragEventArgs e)
{
string strText = "";
if (e.Data.GetDataPresent(DataFormats.Text))
{
strText = (string) e.Data.GetData(DataFormats.Text);
}
listBox2.Items.Add(strText);
listBox1.Items.Remove(strText);
}
}
}
I'm trying to create an application that takes item from listbox and adds them to another by clicking a button. The application adds items to the listbox fine but i'm trying to avoid duplicates. When one item is added i want it to make sure that the item isn's already there. The item is removed when the button is clicked so the duplicate issue is avoided there but when the item is added via drag and drop it doesn't check for duplicates.