Home Forums WinForms controls Xceed Grid for WinForms GridComboBox & Sorting Reply To: GridComboBox & Sorting

User (Old forums)
Member
Post count: 23064

Try creating a new Icomparer class and set the DataComparer class to a new instance of thie class like:

column.DataComparer = New ComboBoxComparer();

In the ComboBoxComparer compare the DisplayMember that maps to the ValueMember that would normally be compared in the Default Comparer.

public class ComboBoxComparer: IComparer

{

public ComboBoxComparer()

{

}

int IComparer.Compare( object x, object y )

{
string xDisplay;
string yDisplay;

switch (x)
{
case 1:
xDisplay = “First DisplayMember;
break;
case 2:
xDisplay = “SecondDisplayMember;
break;
default:
xDisplay = “OtherDisplayMember”;
break;
}

switch (y)
{
case 1:
yDisplay = “First DisplayMember;
break;
case 2:
yDisplay = “SecondDisplayMember;
break;
default:
yDisplay = “OtherDisplayMember”;
break;
}

return ( xDisplay ).CompareTo( yDisplay );

}

}

Imported from legacy forums. Posted by Kareem (had 3123 views)