473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A question about enums, TypeConverters and DataGrids

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.

Mar 1 '07 #1
0 1272

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
3
by: Dave Girvitz | last post by:
I have a PropertyGrid (Windows Forms App) based component that uses TypeConverters to generate ranges of acceptable values for properties. The idea was that I could download the key/value pairs...
1
by: Smoke | last post by:
Im sure i have asked this about 5 months ago, and someone sent me an interesting article about how to do what i need, but i lost it.. Im developing a custom control and i would need to have nested...
0
by: ljlevend | last post by:
I need to create TypeConverters for the floating type drawing structures (i.e., PointF, SizeF and RectangleF) that behave exactly as their integer couterparts (e.g., System.Drawing.PointConverter)....
2
by: Simon Elliott | last post by:
I have some legacy C++ code which requires some enums to be 1 or 2 bytes in size. I'd ideally like to be able to specify that a few carefully selected enums are a particular size. By default,...
1
by: tony | last post by:
Hello! I find it hard to understand this about TypeConverter. I have read some documentation but still it's hard to understand. For example this row below. Can somebody write some small code...
37
by: mdh | last post by:
In one of the answers to a K&R exercise, the first couple of lines are: enum loop { NO, YES}; enum loop okloop=YES; I get the first line, but not the second. Sorry about the LOL question. ...
0
by: herpers | last post by:
Hi, I'm writing a control with a lot of properties, that are not directly supported by the propertygrid. I can work around this by writing typeconverters, that do the job for me, but I think for...
3
by: =?Utf-8?B?R3JlZyBDbGFyaw==?= | last post by:
I have an object which I present to the user through a propertyGrid. With many of the properties (many of which are objects themselves) I have implemented my own TypeConverters; many of these...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.