Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

i want to perform the drag and drop for items in a list box. list box items source is the collection List.
i have two list boxes. listbox1 contains all the items. i will drag and drop the selected items from list box1 to list box2(the items should be copied to listbox2). now in listbox2 again i want to drag and drop items with in the listbox2 to reorder the items.

but,when i do drag and drop of items with in the list box2 the items are added at the end of the list. i want to insert the item right where the user drops the item in the list box2.

i am able to get the index of selected item and remove from the list, but in WPF how to get the index of the item in the list where user drops the item so that i can insert the item to the list at that index.

Thanks in advance,
Posted
Updated 9-Nov-11 23:32pm
v4

1 solution

You should use the Insert method of the collection the ListView is bound to, instead of the Add method. To find the index of the items either side of the position the drop item is dropped, you are going to have to use the <a href="http://msdn.microsoft.com/en-us/library/ms608752.aspx">VisualTreeHelper.HitTest</a>[<a href="http://msdn.microsoft.com/en-us/library/ms608752.aspx" target="_blank" title="New Window">^</a>] method to find this. This method returns a Point, which you can compare to the e.Position property of the Drop handler for your ListView. Sounds complicated, and is, somewhat - Good Luck!
 
Share this answer
 
Comments
KiranBabu M 10-Nov-11 5:29am    
sorry i am unable to find the index of the drop location item.
is there any other way to do it in WPF?
Wayne Gaylard 10-Nov-11 5:37am    
Did you try the HitTest method and what did you get?
KiranBabu M 10-Nov-11 8:14am    
null

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