Home Forums WinForms controls Xceed Grid for WinForms GridComboBox & Sorting

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12896 |

    I have CellEditor and CellViewer properties of grid columns set to GridComboBox. Everything works fine exept sorting those columns. Grid control sorts according to ValueMember of GridComboBox instead of DisplayMember. Average user can see it as “random sorting”, as they do not see ValueMember values at all.
    Any ideas how to solve that ?

    Best Reagrds

    Simon

    Imported from legacy forums. Posted by Szymon (had 2088 views)

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.