2 Implement handlers for at least these 3 events.
Ensure that AllowDragDrop is set to true. 2 Implement handlers for at least these 3 events private void myList_ItemDrag(object sender, ItemDragEventArgs e) { DoDragDrop(e. Item, DragDropEffects.
Link); } private void myList_DragEnter(object sender, DragEventArgs e) { e. Effect = DragDropEffects. Link; } private void myList_DragDrop(object sender, DragEventArgs e) { // do whatever you need to reorder the list.
} Getting the index of the row you dropped onto may look something like Point cp = myList. PointToClient(new Point(e. X, e.
Y)); ListViewItem dragToItem = myList. GetItemAt(cp. X, cp.
Y); int dropIndex = dragToItem.Index.
1 +1 for the row finding sample. – Adam Houldsworth Jul 26 '10 at 13:25 Thanks, it looks like the method myList_DragDrop will require some tinkering. So to my understanding we're going to have to remove the selected item from the list, and later re-add it to the new index (where we want to drop it?).
Plus, we'd also have to shift down the row that we drop into by one...is there an event that handles this? – Mike Jul 26 '10 at 14:08 the ItemDrag method passes in the entire ListView control into the DragDrog method, in which I am unable to grab the specific item which I've started dragging, any suggestions? Private void empList_ItemDrag(object sender, ItemDragEventArgs e) { DoDragDrop(e.
Item, DragDropEffects. Link); empList.Items. RemoveAt(empList.
SelectedIndices0); } private void empList_DragDrop(object sender, DragEventArgs e) { Point cp = empList. PointToClient(new Point(e. X, e.
Y)); ListViewItem dragToItem = empList. GetItemAt(cp. X, cp.
Y); int dropIndex = dragToItem. Index; } – Mike Jul 26 '10 at 16:25.
I know this isn't ListView specific, but I have sample code for implementing row drag and drop out of / into a DataGridView. Some of it is obviously control specific, other code is actually pretty generic (such as deciding when its a drag): adamhouldsworth.blogspot.com/2010/01/dat... Completely forgot the fact that ListView already allows drag-dropping! I can also add some theory - when the drop occurs on your control, you will need to hit test on those coordinates (likely a method called tTest) on the ListView to see what row was hit, this is the basis for where to insert the row being dragged.
Unrelated - is that var class perhaps the new var keyword in C#?
We thought ListView allows drag-dropping however besides the property allowdrop = true, we can not find any automagic logic that moves the rows around for us. Which is why it looks like implementing it with events (like the post above) is what is required. The var attribute came into question when we looked at the following post: stackoverflow.Com/questions/643275/c-drag-drop-in-listview – Mike Jul 26 '10 at 14:12 @Mike yea I realised when I spotted the other post, hence I struck out the relevant part of my answer.
What I didn't realise was that the ListView has a GetItemAt method - encapsulating the hit test nicely for you. Using that, all that was needed was to remove the row and insert it at the given index - 1. Also, in that post is the new var keyword - just means the compiler infers the type for you - syntactic sugar.
– Adam Houldsworth Jul 26 '10 at 14:24 the ItemDrag method passes in the entire ListView control into the DragDrog method, in which I am unable to grab the specific item which I've started dragging, any suggestions? Private void empList_ItemDrag(object sender, ItemDragEventArgs e) { DoDragDrop(e. Item, DragDropEffects.
Link); empList.Items. RemoveAt(empList. SelectedIndices0); } private void empList_DragDrop(object sender, DragEventArgs e) { Point cp = empList.
PointToClient(new Point(e. X, e. Y)); ListViewItem dragToItem = empList.
GetItemAt(cp. X, cp. Y); int dropIndex = dragToItem.
Index; } – Mike Jul 26 '10 at 15:16 I think this comment would be best against Matthew Vines' answer. – Adam Houldsworth Jul 26 '10 at 16:00.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.