Date: 02.01.2019 8:03:14
Date: 02.01.2019 11:20:51
Вот минимальный пример перетаскивания строк:
using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Windows.Forms; using System.Drawing; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); dataGridView1.AllowDrop = true; } private void dataGridView1_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Move; } private void dataGridView1_DragDrop(object sender, DragEventArgs e) { Point p = dataGridView1.PointToClient(new Point(e.X, e.Y)); int TargetRow = dataGridView1.HitTest(p.X, p.Y).RowIndex; int DraggedRow = (int)e.Data.GetData(typeof(int)); if (TargetRow < 0 || DraggedRow < 0 || TargetRow >= dataGridView1.Rows.Count-1 || DraggedRow >= dataGridView1.Rows.Count-1 || TargetRow == DraggedRow) return; var row = dataGridView1.Rows[DraggedRow]; dataGridView1.Rows.RemoveAt(DraggedRow); dataGridView1.Rows.Insert(TargetRow, row); } private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button.HasFlag(MouseButtons.Left)) { int DraggedRow = e.RowIndex; DragDropEffects dropEffect = dataGridView1.DoDragDrop((object)DraggedRow,DragDropEffects.Move); } } } }
Автор: VadimTagil