Sorting Users in a Group
Posted: Fri Sep 16, 2011 12:06 pm
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
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