There’s a list of objects, each object representing a record from a database. To sort the records there is a property called SortOrder. Here’s a sample object:
public class GroupInfo
{
public int Id { get; set; }
public string Text { get; set; }
public int SortOrder { get; set; }
public GroupInfo()
{
Id = 0;
Text = string.Empty;
SortOrder = 1;
}
}
A list object would look like this:
var list = new List<GroupInfo>();
I need to be able to change the SortOrder and update the SortOrder on the other objects in the list. I figured out how to sort up or down by one. I need to know how to change it by more than one and adjust the SortOrder on the other records. Any ideas?
This could be done by first getting the original
SortOrderand the updatedSortOrder. You would then iterate through your collection and adjust theSortOrderof any otherGroupInfoobjects that fall inside the range betweenoriginalandupdated. you could put all of this in a “SetSortOrder” function that takes in the containing collection.Update: As suggested, I moved the logic into a static helper function.