Hi,
I have a datagrid that currently displays seeded data.
The datagrid is ordered by a column I have called priority which is just numbers (1, 2 ,3 ,4 etc).
What I am trying to achieve is if i drag the row which has a priority of 3 and drop it on top of row which has a priority of 1, changes priority 3 to 1 and then loops through the other rows to order them accordingly (2, 3, 4).
So my final outcome after drop event would have the priority column like 1, 2, 3, 4.
private void jobListView_Drop(object sender, DragEventArgs e)
{
var records = jobListView.View.Records;
int rowCount = records.Count;
foreach (var record in records)
{
Job job = (Job)(record.Data);
if (job.Priority <= jobListView.SelectedIndex)
{
job.Priority++;
}
else if(job.Priority > jobListView.SelectedIndex)
{
job.Priority--;
}
}
}
The code above does not work but this was my starting point and i am not sure how else to go about it
Hi Alessandro Cirignaco,
Your requirement to maintain the priority column (ex: 1, 2, 3, 4) while drag
drop the records on the top in SfDataGrid can be achieved by customizing the Drop
event. Please refer to the below code snippet,
|
private void OnDrop(object sender, DragEventArgs e) { var records = jobListView.View.Records;
foreach (var record in records) { OrderInfo job = (OrderInfo)(record.Data);
//here get the row index of the record var rowIndex = jobListView.ResolveToRowIndex(record.Data);
//here get the recordInde index of record var recordIndex = jobListView.ResolveToRecordIndex(rowIndex);
//record index starting from 0. So, we need set the plus one value for all records //here set the value for Priority column job.Priority = recordIndex + 1;
} } |
Please find the sample in the attachment.
UG Link: https://help.syncfusion.com/wpf/datagrid/helpers
If we misunderstood your requirement, please provide more information regarding
the requirement. This would help us to proceed further.
Regards,
Vijayarasan S
Hi Vijayarasan,
Thank you for the response. From what i can see in the backend this seems to work. However it is not updating on the datagrid front end.
Can the Datagrid be refreshed?
I managed to get it to work, Thanks for your help
Hi Alessandro Cirignaco,
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
Regards,
Vijayarasan S