Sai Stuff to Developers

May 26, 2008

Drag and Drop Feature In Windows .Net Form

Filed under: DotNet — tosaik @ 12:46 pm
Tags:

On the browser we can develop a Drag and Drop feature using JavaScript, but what the same Drag and Drop feature can we implement in Windows Form? Yes we can how we will learn now.

 

Please Follow the Steps below where I am demonstrating this concept using simple Example.

 

1)      Open visual Studio’s IDE and create a new windows Form using any language which support s by .NET Framework.

2)      On the new for add two listbox controls from toolbox and name it as ListSource and ListTarget.

3)      Now bind the ListSource Listbox to a Datasource (My motive is to fill the Listbox with some data).

4)      In Listsource properties set AllowDrop to True, this will create a new set of events for the control. In the event list of this control doubleClick on Mousedown Event and write this code:

 

ListSource.DoDragDrop(ListbSource.SelectedItem.ToString,DragDropEffects.Copy)

      

5)      In properties of ListTarget Control Set AllowDrop to True.

6)      In properties of ListTarget Control, go to Event block and double Click on DragEnter Event and write this code:

 

e.Effect = DragDropEffects.Copy

 

7)      In properties of ListTarget Control, go to Event block and double Click on DragDrop Event and write this code:

 

LbTarget.Items.Add(e.Data.GetData(DataFormats.Text))  

 

Now Execute or press F5 to see the Out put now select one item in ListSource listbox and drag It to ListTarget listbox  it will add one item in Target list box.

 

This is a simple example I didn’t explained about what is this DragDropEffect Enumerations, for now  just use as I shown I will explain in my next post.

 

I hope this post helps U..,

Thank you  J

 

Create a free website or blog at WordPress.com.

%d bloggers like this: