Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GK2] Add ability to reorder grid rows in streamline input plugin #595

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading