diff --git a/projects/plugins/GKFlowInputPlugin/FlowInputDlg.Designer.cs b/projects/plugins/GKFlowInputPlugin/FlowInputDlg.Designer.cs index 1b9f81563..571238ac6 100644 --- a/projects/plugins/GKFlowInputPlugin/FlowInputDlg.Designer.cs +++ b/projects/plugins/GKFlowInputPlugin/FlowInputDlg.Designer.cs @@ -384,7 +384,8 @@ private void InitializeComponent() this.sgData.TabIndex = 4; // // dataGridView1 - // + // + this.dataGridView1.AllowDrop = true; this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; @@ -393,7 +394,10 @@ private void InitializeComponent() this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Size = new System.Drawing.Size(609, 177); this.dataGridView1.TabIndex = 0; - // + this.dataGridView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.dataGridView_DragDrop); + this.dataGridView1.DragOver += new System.Windows.Forms.DragEventHandler(this.dataGridView_DragOver); + this.dataGridView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dataGridView_MouseMove); + // // cbPersonLink // this.cbPersonLink.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; diff --git a/projects/plugins/GKFlowInputPlugin/FlowInputDlg.cs b/projects/plugins/GKFlowInputPlugin/FlowInputDlg.cs index 853bad253..eec714fde 100644 --- a/projects/plugins/GKFlowInputPlugin/FlowInputDlg.cs +++ b/projects/plugins/GKFlowInputPlugin/FlowInputDlg.cs @@ -19,6 +19,7 @@ */ using System; +using System.Drawing; using System.Threading.Tasks; using System.Windows.Forms; using BSLib; @@ -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 } }