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.

SfDataGrid Row drag to reorder when using Grouping

Thread ID:

Created:

Updated:

Platform:

Replies:

130764 May 31,2017 09:50 PM Jun 3,2017 04:27 PM Xamarin.Forms 3
loading
Tags: SfDataGrid
Michael Eick
Asked On May 31, 2017 09:50 PM

I have a SfDataGrid, and am using the row drag to let the user reorder steps; the item source is  List<StepDTO>, and mu code is like this:

private void SfGrid_QueryRowDragging(object sender, QueryRowDraggingEventArgs e)
{
 if (e.Reason == QueryRowDraggingReason.DragEnded)
 {
  int startIdx = e.From - 1;
  int endIdx = e.To - 1;
  StepDTO s = m_plan.StepList[startIdx];
  m_plan.StepList.RemoveAt(startIdx);
  m_plan.StepList.Insert(endIdx, s);
 }
}

This works great, and I like this control! But now I want to use Grouping, and got it in place and working fine. But, when the RowDragging event is called, the indexes are NOT my item indexes but rather the grid indexes which include the group header rows. So ... crash me.

I am hacling something up that might work, but would rather find out I am missing an easy trick!
Any ideas?

Thanks, Mike



Pavithra  Sivakumar [Syncfusion]
Replied On June 1, 2017 02:04 PM

Hi Michael, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query. We have prepared a sample based on it which can be downloaded from the below link. 
 
 
Regards, 
Pavithra S 


Michael Eick
Replied On June 1, 2017 09:29 PM

Thanks for the quick response. A couple of questions:1. Is it true that this code only allows drag within a group?2. What is the Task.Delay(3000) for? 3 seconds is a long time ...EDIT: Implemented the sample, but the sfGrid.CurrentItem is always null. Sigh.Regards, Mike

Pavithra  Sivakumar [Syncfusion]
Replied On June 3, 2017 04:27 PM

 
Hi Michael, 
 
1.     Regarding your first query of “Is it true that this code only allows drag within a group?” 
 
Yes, it allows drag only within a group. If you want drag among all groups, please refer the below code example. 
 
private void DataGrid_QueryRowDragging(object sender, QueryRowDraggingEventArgs e) 
{ 
       if (e.Reason == QueryRowDraggingReason.DragEnded) 
       { 
             if (dataGrid.GroupColumnDescriptions.Count == 0) 
             { 
 
                    int startIndex = e.From - 1; 
                    int endIndex = e.To - 1; 
                    OrderInfo orderInfo = viewModel.OrdersInfo[startIndex]; 
                    viewModel.OrdersInfo.RemoveAt(startIndex); 
                    viewModel.OrdersInfo.Insert(endIndex, orderInfo); 
             } 
             else 
            { 
                     var currentOrderInfo = e.CurrentRowData as OrderInfo; 
                     var draggedOrderInfo = e.RowData as OrderInfo; 
                     int currentOrderInfoCollectionIndex = this.viewModel.OrdersInfo.IndexOf(currentOrderInfo); 
                     int draggedOrderInfoCollectionIndex = this.viewModel.OrdersInfo.IndexOf(draggedOrderInfo); 
                     viewModel.OrdersInfo.Remove(draggedOrderInfo); 
                     if (e.From > e.To) 
                         viewModel.OrdersInfo.Insert(currentOrderInfoCollectionIndex, draggedOrderInfo); 
                     else 
                         viewModel.OrdersInfo.Insert(currentOrderInfoCollectionIndex + 1, draggedOrderInfo);                          
              } 
      } 
} 
 
2.     Regarding your second query of “ What is the Task.Delay(3000) for? 3 seconds is a long time ...”  
 
Task.Delay is to improve the performance. You can reduce the delay time for your convenience. 
 
3.     Regarding your third query of “Implemented the sample, but the sfGrid.CurrentItem is always null.” 
 
Sorry for the mistake. This condition is not needed. 
 
Regards, 
Pavithra S 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;