Articles in this section
Category / Section

How to disable drag and drop between FrozenColumns and non-frozen columns

4 mins read

SfDataGrid allows you to disable drag and drop option between FrozenColumns and non-Frozen columns by handling QueryColumnDragging event. QueryColumnDragging event occurs multiple times when you drag and also drop the column. You can use Reason property in QueryColumnDraggingEventArgs to identify the reason for the occurrence whether the event is fired while start dragging or dragging or dropping.

 

The QueryColumnDraggingEventArgs object has following properties:

  • Cancel: You can cancel the dragging / dropping action by setting this property to false.
  • PopupPosition: You can get position of point where you drag or drop.
  • From: It denotes column index of the column dragged / that is to be dragged.
  • To: It denotes the column index where mouse is placed over.
  • Reason: The property of enum type QueryColumnDraggingReason with DragStarting, DragStarted, Dragging, Dropping and Dropped enum values that denotes the action.

 

Based on the Reason property in QueryColumnDraggingEventArgs, you can handle the drag and drop option. Here when the Reason is QueryColumnDraggingReas on.Dropping and if the column is dragged from frozen region to non-Frozen region or non-frozen region to frozen region, then you can cancel the dropping action by setting e.Cancel to true.

C#

using Syncfusion.UI.Xaml.Grid;
 
this.datagrid.QueryColumnDragging += datagrid_QueryColumnDragging; 
 
void datagrid_QueryColumnDragging(object sender,
                                                               QueryColumnDraggingEventArgs e)
{
     if (e.Reason == QueryColumnDraggingReason.Dropping)
    {  
           //used to get frozen column index from the  frozen column count
           var frozencolindex = datagrid.FrozenColumnCount +           
                                             this.datagrid.ResolveToStartColumnIndex();             
           //cancels dragging from frozen column to non-frozen column
           if (e.From < frozencolindex && e.To > frozencolindex - 1)
                 e.Cancel = true;
           // cancels dragging from non-frozen column to frozen column
           if (e.From > frozencolindex && e.To < frozencolindex || 
                (e.From == frozencolindex && e.To < frozencolindex))
                     e.Cancel = true;
    }
}

 

You can refer to the following sample links to disable the drag and drop between frozen column and non-frozen column for WPF platforms.

WPF: DragAndDropbetweenFrozenColumn.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied