We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Inserting a row using DnD

Your drag and drop capability is very nice. I can go from one grid to another or within a grid. Is there a property or method for dropping a row in the middle of a grid without overwriting an existing row? Thanks, Paul

3 Replies

AD Administrator Syncfusion Team October 14, 2003 09:38 PM UTC

No, but you can catch the DragDrop event and insert a row at that point to catch the dropped row.
private void gridControl1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
	Point pt = this.gridControl1.PointToClient(Control.MousePosition);
	int row, col;
	this.gridControl1.PointToRowCol(pt, out row, out col, -1);

PM Paul Muller October 15, 2003 04:11 PM UTC

Unless I converted your code to VB improperly, there seems to be a bug. When I have a grid with 5 rows and I try to drag row 4 to tow 1, the result is 4, 1, 2, blank, 4, 5 instead of 4, 1, 2, 3, 5. Row 3 has disappeared! Here is my code: Private Sub GridControl2_DragDrop1(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles GridControl2.DragDrop Dim pt As New Point pt = Me.GridControl2.PointToClient(Control.MousePosition) Dim row, col As Integer Me.GridControl2.PointToRowCol(pt, row, col) If Len(Me.GridControl2(row, 1).CellValue) > 0 Then Me.GridControl2.Rows.InsertRange(row, 1) End If ''''Me.GridControl2.Rows.RemoveRange(rowFrom, 1) End Sub

AD Administrator Syncfusion Team October 15, 2003 06:23 PM UTC

When you drag a higher numbered row to a lower numbered row in the same grid, then inserting the new row for the dropped effectively increases the source row number by 1. This means that when the OLE code goes onto clear the source row, it clears the row immediately preceding the source row. The OLE D&D code has no knowledge that you have inserted a row above the source row. So, if you need this functionality, you will have to work around this problem. Attached is one try at this. It uses the Clearing cells event to try to clear the proper row. It assumes you are only dragging 1 row. If you want to support dragging multiple rows, then you would have to extend this code to handle that.

Live Chat Icon For mobile
Up arrow icon