C # Listview Drag and Drop Lines

I am trying to implement row permutation and C # drag and drop with a list that will then update the SQL database with the current row order. I came across some snippets of code on the Internet (one of this website that implemented the "var" class), but none of them work with my needs. I do not need help updating the database, since I have a good idea how I will do it, but I can not get the line to reorder the work correctly, any input will be appreciated.

-Thanks

m & a

+7
c # listview drag-and-drop
source share
2 answers
  • Verify that AllowDragDrop is set to true.

2 Implement handlers for at least these three 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 fell on might look something like this:

 Point cp = myList.PointToClient(new Point(eX, eY)); ListViewItem dragToItem = myList.GetItemAt(cp.X, cp.Y); int dropIndex = dragToItem.Index; 
+14
source share

I know this is not a ListView specification, but I have some sample code to implement dragging a row from / to a DataGridView . Some of them are obviously control-specific, other code is actually quite general (for example, the decision to drag it):

http://adamhouldsworth.blogspot.com/2010/01/datagridview-multiple-row-drag-drop.html

I completely forgot the fact that ListView already allows drag-dropping!

I can also add some theory - when the drop occurs on your control, you need to click a test for these coordinates (probably a method called HitTest ) on the ListView to see which row was deleted, this is the basis for where to insert the row, draggable.

Unbound is the var class, perhaps the new var keyword in C #?

0
source share

All Articles