Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i make dragDrop for items fro listView to drop location in the userControl
note: i want to access the item and its properties after drop it
i know i should drop it as object but i dont know how!
Posted
Comments
BillWoodruff 29-Nov-14 18:01pm    
Are you speaking of drag-dropping a ListViewItem into another ListView in a UserControl ? Or ... ?
M. Daban 30-Nov-14 1:14am    
drag-dropping a ListViewItem into UserControl in any position

1 solution

Yes, it's possible, using standard techniques, to detect a 'Drop of any type of Object on the surface of a UserControl, and it's possible to detect the Type of the Object dropped:
C#
private void YourUserControl1_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetFormats().Contains("System.Windows.Forms.ListViewItem"))
    {
        ListViewItem droppedLVItem = e.Data.GetData(typeof (ListViewItem)) as ListViewItem;
        // make a copy ?
        ListViewItem clonedItem = (ListViewItem) droppedLVItem.Clone();

        // Now what ?
    }
}

private void YourUserControl1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}
So: let's say you detect a drop of a ListViewItem at position 100,200 in your UserControl, and there's no Control at that location that could "swallow" the drop (like another ListView): what do you want to show/create in the UserControl at that point ?

A ListViewItem is not a Control: you can't add it to the UserControl's Control Collection.

So, what do you want to do: construct some new user-interface object, and put some representation of the ListViewItem's data into, or on, it ?

Or, do you wish to use the ListViewItem's data to make changes in your UserControl's other Controls, or data-structures ?

Voting on solutons, and choosing an accepted solution when you get a response that answers your question to your complete satisfaction, is a way you can contribute to the long-run value of QA on CodeProject.
 
Share this answer
 
v2

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