/// <summary> /// Only allow drop if over a row or a row header but not within the current selection /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void dlList_DragOver(object sender, DragEventArgs e) { DataListBeginDragEventArgs dragArgs = (DataListBeginDragEventArgs)e.Data.GetData( typeof(DataListBeginDragEventArgs)); DataListHitTestInfo hti = dragArgs.Source.HitTest(dlList.PointToClient(Cursor.Position)); if ((hti.Type & DataListHitType.RowOrHeader) != 0 && (hti.Row < dragArgs.SelectionStart || hti.Row > dragArgs.SelectionEnd)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } }
/// <summary> /// Handle the drop operation. This doesn't do anything interesting yet. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void dlList_DragDrop(object sender, DragEventArgs e) { if (!e.Data.GetDataPresent(typeof(DataListBeginDragEventArgs))) { return; } DataListBeginDragEventArgs dragArgs = (DataListBeginDragEventArgs)e.Data.GetData( typeof(DataListBeginDragEventArgs)); DataListHitTestInfo hti = dragArgs.Source.HitTest(dlList.PointToClient(Cursor.Position)); if ((hti.Type & DataListHitType.RowOrHeader) != 0 && (hti.Row < dragArgs.SelectionStart || hti.Row > dragArgs.SelectionEnd)) { MessageBox.Show(String.Format("Selection dropped on row {0}", hti.Row + 1)); dlList.MoveTo(hti.Row); dlList.Select(hti.Row, hti.Row, hti.Row); } }