I have an enum and I want to customize the order it appears in the drop-down of a property grid.
public enum Dir : int { None = 0, North = (1 << 1), South = (1 << 2), East = (1 << 3), West = (1 << 4), NorthWest = North | West, NorthEast = North | East, SouthWest = South | West, SouthEast = South | East }
I want the drop-down to appear in the same order as I have declared the enum, but instead it sorts into numerical order.
I know it’s possible to do with a type converter, but is it possible to do it without?
Are those values fixed? I assume you’re using a pseudo-flags-like enum to allow you to find out whether the value is ‘at all northlike’. If that’s the case (and it is a bit odd – it means you can have
South | North, but never mind) would it matter if you set an extra bit as well?That will keep it in numerical order. (It would be easier and more consistent if you could either make West come before East, or NorthEast come before NorthWest etc. Then you could just use
(1 << 5)as the extra bit for all of them.