PDA

Click to See Complete Forum and Search --> : dragging large icons in a listview ( like windows explorer )


dynamic_sysop
Jan 2nd, 2004, 06:14 PM
I've built a little example which allows you to drag listview items around ( in large icon view ) and drop them at any given point of the same listview...

[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="SendMessageA")]
static extern int SendMessage (System.IntPtr hwnd, int wMsg, int wParam,ref Point lParam);
const int LVM_SETITEMPOSITION32 = (0x1000 + 49);

private void ListView1_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
ListViewItem lvi =(ListViewItem)e.Item;
ListView1.DoDragDrop(new DataObject("System.Windows.Forms.ListViewItem", lvi), DragDropEffects.Move);
}

private void ListView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if(e.Data.GetDataPresent("System.Windows.Forms.ListViewItem"))
{
e.Effect = DragDropEffects.Move;
}
}

private void ListView1_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
ListViewItem lvi =(ListViewItem)e.Data.GetData("System.Windows.Forms.ListViewItem");
Point pnt=new Point(e.X - (this.Location.X + ListView1.Location.X + 40), e.Y - (this.Location.Y + ListView1.Location.Y + 75));
SendMessage(ListView1.Handle, LVM_SETITEMPOSITION32, lvi.Index,ref pnt);
e.Effect = DragDropEffects.Move;
}

i've included a source project ...