Click here to Skip to main content
16,018,805 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
plz rply
I want to small demo of drag drop control with design
Posted
Updated 8-May-13 1:03am
v2
Comments
Jochen Arndt 8-May-13 2:54am    
The question is unclear.

If you want to drag text from one control to a text box, the 'label' control must support drag operations and the text box must support drop operations. This is not implemented in standard Windows controls beside the rich edit control.

When using MFC, this can be implemented using the COleDataSource and COleDropTarget classes. These use the COM interfaces IDragSource and IDropTarget.
[no name] 8-May-13 7:15am    
This is still not a question or a description of a problem. You either need to search for an example of what you want, probably thousands of examples exist, or write one yourself.

1 solution

For drop:
For drag and drop:
1) Set the AllowDrop property of your form to True
2) Create a handler for both the DragEnter and DragDrop events of your form.
3) In the DragEnter handler, add the following line of code:
e.Effect = DragDropEffects.Move;

4) In the DragDrop handler, add the following:
C#
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
if (files != null)
    {
    foreach (string file in files)
        {
        Console.WriteLine(file); // Or whatever you need to do...
        }
    }
(this shows file drop, there are other formats available)

For Drag:
Handle MouseMove and create a StringCollection, then the DataObject, then do the DragDrop:
C#
private void dgvTracks_MouseMove(object sender, MouseEventArgs e)
    {
    DataGridView dgv = sender as DataGridView;
    System.Collections.Specialized.StringCollection filePath = new System.Collections.Specialized.StringCollection();
    foreach (DataGridViewRow row in dgv.SelectedRows)
        {
        filePath.Add((string)row.Cells["Path"].Value);
        }
    DataObject dataObject = new DataObject();
    dataObject.SetFileDropList(filePath);
    dgv.DoDragDrop(dataObject, DragDropEffects.Copy);
    }
This provides a list of files from a DataGridView.
It's a similar procedure depending on what you want to drag out of your control(s)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900