How to get ListViewItem under MouseCursor while dragging sth. above him

I implement drag and drop in a ListView. I already managed to get the ListViewItem under the cursor when deleting it, but I would like to get the ListViewItem under the mouse cursor while I drag sth. over ListView-Control.

I would like to select ListViewItem (selected = true), as in Windows Explorer when you drag and drop files around a folder.

I was thinking of events like ItemMouseHover, MouseMove in ListView, but they don't fire when dragging sth. above him.

I hope you help me ...

Hello,

Inno

PS: I am using .Net2.0

+3
source share
2 answers

DragOver listview? .

private void listBox_DragOver(object sender, 
  DragEventArgs e)
{
  //for ListView
  var point = listView.PointToClient(new Point(e.X, e.Y));
  var item = listView.GetItemAt( point.X, point.Y);     
  if(item != null)
  {
     //do whatever - select it, etc
  }


  //or, for ListBox 
  var indexOfItem = 
    listBox.IndexFromPoint(listBox.PointToClient(new Point(e.X, e.Y)));
  if (indexOfItem != ListBox.NoMatches)
  {
     //do whatever - select it, etc
  }
}
+2

ListView, , ObjectListView ( .NET WinForms ListView).

ObjectListView ListView, , , .

+1

Source: https://habr.com/ru/post/1720458/


All Articles