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.
Unfortunately, activation email could not send to your email. Please try again.

How to Drag and Drop a Row from one Detailsview to another Detailsview in the SfDataGrid?

In the SfDataGrid, it is not possible to perform row drag and drop operation within a grid and from one SfDataGrid to another, by default. You can achieve this by deriving new class from the GridSelectionController class in the SfDataGrid. Refer to the links RowDragandDropwithinGrid, RowDragandDrop-OneSfDataGridtoanother for more information.

Likewise, you can perform row drag and drop operations from one Detailsview to another Detailsview by deriving new class from the GridSelectionController and overriding its virtual method, HandlePointerOperations().

To handle Drag and Drop of data, you need to wire the following VisualContainer’s events in the derived SelectionController class:

  • PreviewMouseMove
  • PreviewDrop

You need to instantiate the instance of the new class, GridSelectionControllerExt that is derived from the GridSelectionController for the DetailsView DataGrid’s SelectionController property to achieve the Drag and Drop between two DetailsViewGrid as shown in the following code example.

 

C#

 

The following code example shows how to derive a new class from the GridSelectionController.

 

C#

The earlier mentioned VisualContainer event is wired and unwired in the Loaded and Unloaded events of the SfDataGrid as shown in the following code example.

C#

 

HandlePointerOperations

In the HandlePointerOperations() virtual method, you can set IsPointerPressed to true when the mouse pointer is pressed on the row of any of the two Detailsview DataGrid and you can also set IsPointerPressed to false when the mouse pointer is released.

The following code example illustrates how to override the HandlePointerOperations() virtual method in the GridSelectionController class.

 

C#

 

Row Dragging

You can drag the row data from one DetailsviewGrid to another DetailsviewGrid or vice versa in the PreviewMouseMove event of the VisualContainer. You can get the corresponding row and column index based on the mouse pointer position by using the PointToCellRowColumnIndex () method in the VisualContainer.

You need to resolve the record index by the ResolveToRecordIndex() helper method in the SfDataGrid to retrieve the exact row data on view under mouse position. Now, drag the record with the specified DragDropEffects by using the WPF DragAndDrop as illustrated in the following code example.

C#

 

Dropping

You can perform the Drop operation by using the PreviewDrop event of the VisualContainer. The PreviewDrop event is fired when the row data is dropped into a particular position of the SfDataGrid. You need to check whether the dragged record and the DataGrid is matched with specified format and the dragged record is inserted into a particular position of the DetailsviewGrid as shown in the following code example.

C#

 

You can refer to the following link for Drag-and-Drop row from one DetailsviewGrid to another DetailsviewGrid in the WPF platform.

Sample:

WPF

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
4184 02/28/2015 04/05/2017 WPF SfDataGrid 4.5 12.4.0.24
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.