Page 1 of 1

Sorting Users in a Group

Posted: Fri Sep 16, 2011 12:06 pm
by egormsen
I have created a user group and I need to display those users in a drop down list for selection. I want to be able to present those users sort by last name. So am trying to use the IComparer for the UserCollection (I found some similar code posted on the forums), but am having a problem.


Here is the iComparer class that I have created:

public class UserComparer : IComparer
{
SortDirection _SortDirection;
public UserComparer(SortDirection sortDirection)
{
_SortDirection = sortDirection;
}

#region IComparer Members
public int Compare(object x, object y)
{
if (_SortDirection == SortDirection.Ascending)
return ((User)x).PrimaryAddress.LastName.CompareTo(((User)y).PrimaryAddress.LastName);
return ((User)y).PrimaryAddress.LastName.CompareTo(((User)x).PrimaryAddress.LastName);
}
#endregion
}

Then here is the code where I am retrieving the User group and then trying to sort it by the Last Name of the user (which I am getting from Primary Address).

UserCollection AcctGroup = CommerceBuilder.Users.UserDataSource.LoadForGroup(17);
AcctGroup.Sort(new UserComparer(SortDirection.Ascending)); ****** This line is the problem

In visual studio it is giving me the error

"The best overloaded method match for 'CommerceBuilder.Common.SortableCollection<CommerceBuilder.Users.User>.Sort(string)' has some invalid arguments

Any ideas what what I am missing here?

Thanks,

Eldon

Re: Sorting Users in a Group

Posted: Tue Sep 20, 2011 9:16 am
by mazhar
I am not sure why its not working for you. I just made few tests with the code you posted and its working for me.