private void dgvImages_RowMoving(object sender, Controls.RowMovingEventArgs e) { if (e.Source == dgvImages) { _images.MoveRange(e.SourceRows[0].Index, e.SourceRows.Count, e.Destination); } }
protected override void OnDragDrop(DragEventArgs drgevent) { if (drgevent == null || !drgevent.Data.GetDataPresent(typeof(DataGridViewMovedRows)) || HitRowIndex < 0) { base.OnDragDrop(drgevent); return; } int newIndex = GetDragHitTestInfo(drgevent).ActualDestination; if (newIndex < 0) { return; } var dgdo = (DataGridViewMovedRows)drgevent.Data.GetData(typeof(DataGridViewMovedRows)); RowMovingEventArgs ev = new RowMovingEventArgs(dgdo.Source, dgdo.SourceRows, dgdo.SetRow, newIndex); OnRowMoving(ev); if (!ev.Cancel) { foreach (var row in dgdo.SourceRows) { dgdo.Source.Rows.Remove(row); } Rows.InsertRange(newIndex, dgdo.GetModifiedRows()); ClearSelection(); for (int i = newIndex; i < newIndex + dgdo.SourceRows.Count; i++) { SetSelectedRowCore(i, true); } OnRowMoved(EventArgs.Empty); } HitRowIndex = -1; }
private void dgvBookmarks_RowMoving(object sender, Controls.RowMovingEventArgs e) { if (e.Source.Name == "dgvImages") { e.Cancel = true; _bookmarks.Insert(e.Destination, new Bookmark() { Target = e.SourceRows[0].Index }); } else if (e.Source == dgvBookmarks) { _bookmarks.Move(e.SourceRows[0].Index, e.Destination); } }
/// <summary><see cref="RowMoving"/> イベントを発生させます。</summary> protected virtual void OnRowMoving(RowMovingEventArgs e) { RowMoving?.Invoke(this, e); }
protected override void OnDragDrop(DragEventArgs drgevent) { if (drgevent == null || !drgevent.Data.GetDataPresent(typeof(DataGridViewMovedRows)) || HitRowIndex < 0) { base.OnDragDrop(drgevent); return; } int newIndex = GetDragHitTestInfo(drgevent).ActualDestination; if (newIndex < 0) return; var dgdo = (DataGridViewMovedRows)drgevent.Data.GetData(typeof(DataGridViewMovedRows)); RowMovingEventArgs ev = new RowMovingEventArgs(dgdo.Source, dgdo.SourceRows, dgdo.SetRow, newIndex); OnRowMoving(ev); if (!ev.Cancel) { foreach (var row in dgdo.SourceRows) dgdo.Source.Rows.Remove(row); Rows.InsertRange(newIndex, dgdo.GetModifiedRows()); ClearSelection(); for (int i = newIndex; i < newIndex + dgdo.SourceRows.Count; i++) SetSelectedRowCore(i, true); OnRowMoved(EventArgs.Empty); } HitRowIndex = -1; }