/// <summary> /// Handle drop from data list /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void txtValue_DragDrop(object sender, DragEventArgs e) { DataRowView drv; StringBuilder sb; if (!e.Data.GetDataPresent(typeof(DataListBeginDragEventArgs))) { return; } DataListBeginDragEventArgs dragArgs = (DataListBeginDragEventArgs)e.Data.GetData( typeof(DataListBeginDragEventArgs)); sb = new StringBuilder("Dropped IDs: "); // Use the data list's currency manager CurrencyManager cm = dlList.ListManager; // Just list the IDs of the selection for (int idx = dragArgs.SelectionStart; idx <= dragArgs.SelectionEnd; idx++) { if (idx != dragArgs.SelectionStart) { sb.Append(','); } drv = (DataRowView)cm.List[idx]; sb.Append(drv["ID"]); } txtValue.Text = sb.ToString(); }
/// <summary> /// Test drag and drop with the data list /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void dlList_BeginDrag(object sender, DataListBeginDragEventArgs e) { // Commit any pending changes before the drag operation begins dlList.CommitChanges(); this.DoDragDrop(e, DragDropEffects.Copy | DragDropEffects.Move); }
/// <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); } }