Friday, December 10, 2010

Drag From First ListBox and Drop it in the Second ListBox

Add two ListBoxes. set the allow drop property of second ListBox to true

private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
listBox2.DoDragDrop(listBox1.SelectedItem , DragDropEffects.Copy);

}

private void listBox2_DragDrop(object sender, DragEventArgs e)
{

listBox2.Items.Add(e.Data.GetData(DataFormats.Text));

}

private void listBox2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
e.Effect =DragDropEffects.None ;

}

0 comments:

Post a Comment