Hi,
So here's my story. I have an enum that's defined so:
[TypeConverter(typeof(AccountKindTypeConverter))]
public enum AccountKind
{
Savings = 0,
Current = 1,
}
I'm using a TypeConverter here as an easy way to localize the enum.
AccountKindTypeConverter basically returns a string from a resource
file. This way, when a DataTable containing a column with AccountKind
is displayed in a DataGrid, it shows me a localized string instead of
the enum name.
So far, so good.
The problem comes in when I try to sort these values in the DataGrid.
Since the table contains the enum values 0 and 1, the grid performs
the sort on these numeric values. So when the column is supposed to be
sorted in alphabetical order, it shows accounts of type "Savings"
before those of "Current", because the enum value for Savings is 0 and
that for Current is 1.
What's an elegant solution? Of course, I could just go in and renumber
my enum values now. At this point I have the luxury of doing that. But
that doesn't work out very well when you think about things like
versioning. Say I release my application and a year later, I need to
add some other type of account. "Checking", for example. Going with
the re-numbering strategy, that would need to go in with the value 0.
Thus completely breaking all my user's existing databases.
What's the right way to solve this problem?
Thanks in advance.