Skip to content

Commit

Permalink
Merge pull request #595 from hazzik/dnd-streamline
Browse files Browse the repository at this point in the history
[GK2] Add ability to reorder grid rows in streamline input plugin
  • Loading branch information
Serg-Norseman authored Aug 27, 2024
2 parents 63ed543 + 2eccc26 commit b7ec656
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
8 changes: 6 additions & 2 deletions projects/plugins/GKFlowInputPlugin/FlowInputDlg.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions projects/plugins/GKFlowInputPlugin/FlowInputDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using BSLib;
Expand Down Expand Up @@ -313,6 +314,53 @@ private void rbX_CheckedChanged(object sender, EventArgs e)
gbMetrics.Enabled = (rbSK_Met.Checked);
}

private void dataGridView_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) != MouseButtons.Left || dataGridView1.SelectedRows.Count == 0) {
return;
}

var rowToMove = dataGridView1.SelectedRows[0];
if (rowToMove.IsNewRow) {
return;
}

dataGridView1.DoDragDrop(rowToMove, DragDropEffects.Move);
}

private void dataGridView_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}

private void dataGridView_DragDrop(object sender, DragEventArgs e)
{
if (e.Effect != DragDropEffects.Move) {
return;
}

var clientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
var hit = dataGridView1.HitTest(clientPoint.X, clientPoint.Y);
var rowIndexOfItemUnderMouseToDrop =
hit.Type != DataGridViewHitTestType.TopLeftHeader && hit.Type != DataGridViewHitTestType.ColumnHeader
? hit.RowIndex
: 0;

var rowToMove = e.Data.GetData(typeof(DataGridViewRow)) as DataGridViewRow;
if (rowToMove == null) {
return;
}

dataGridView1.Rows.Remove(rowToMove);
if (rowIndexOfItemUnderMouseToDrop < dataGridView1.Rows.Count && rowIndexOfItemUnderMouseToDrop >= 0) {
dataGridView1.Rows.Insert(rowIndexOfItemUnderMouseToDrop, rowToMove);
} else {
dataGridView1.Rows.Add(rowToMove);
}

dataGridView1.CurrentCell = rowToMove.Cells[0];
}

#endregion
}
}

0 comments on commit b7ec656

Please sign in to comment.