This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
In our program we use a "DisplayName" attribute (not Microsoft's, which cannot be applied to enum values) to specify how the enum value should be displayed when the default ToString() is not good enough (for example, when we want spaces or punctuation). This works everywhere in our program except in the Mindscape DataGrid header filters. I've been looking at the Mindscape source to see how I could get this working in the header filters. It appears that the crux of the matter is in the ColumnFilter.BuildDescription private method. There appears to be no way I can override this logic (constructor is internal, properties not virtual). I see it does get a TypeConverter from the PropertyInfo, and I can certainly provide a TypeConverter that does the string conversion the way I need it, but I cannot see how to get my TypeConverter into the PropertyInfo. I set up the columns in C# by setting the following properties: DisplayMemberBinding, PropertyType, DisplayTemplate. Is there an existing method I can use to get ColumnFilter to use my enum strings? If not, I see a couple of possibilities for passing my TypeConverter that would require only minor changes to the Mindscape DataGrid: 1) set the TypeConverter attribute on the enum type definition (set to DataGridColumn.PropertyType), which BuildDescription would need to check for, or 2) set a new TypeConverter property on the DataGridColumn, which BuildDescription would also need to check for. My preference would be #2 since I think it would be more efficient and would have no chance of inadvertantly changing how any existing code works. Thanks Peter |
|
|
Hi Peter, Thanks for detailing this. I'll have a look into it over the next week. -Jason Fauchelle |
|
|
Hi Jason, One further note (and at risk of stating the obvious), it seems to me this is also a localization issue as well. Here is a link to a Stack Overflow article that uses an attribute to supply the desired display string for enums, similar to what I am doing: http://stackoverflow.com/questions/17380900/enum-localization Again for such a scheme to work with the Mindscape enum filter we would need the ability to somehow supply the desired alternate display strings. Peter |
|
|
Hi Peter, It looks like this is already supported, but not when using DisplayMemberBinding. I've made an update to get the TypeConverter from attributes on either the property type, or the property itself that DisplayMemberBinding points to. This update will be available in the next nightly build. Your TypeConverter may need to override GetStandardValuesSupported to return true, and GetStandardValues to return a StandardValueCollection containing all the enum values. -Jason Fauchelle |
|
|
Hi Jason, Thanks for the update. However, I find it still doesn't work, and I think I see why. In ColumnFilter.BuildDescription I can see that TypeDescriptor.GetConverter(type) successfully retrieves my type converter, and then EnumValuesConverter.Convert again retrieves my converter the same way (and uses it to get the standard values). However, ObjectFilterDescription, which is responsible for the actual conversion to string, ignores my converter. My suggested change: rather than passing propertyInfo to the constructor of ObjectFilterDescription, just pass the type converter that has already been determined. [Update: I tested this suggested fix and verified that is solves the problem.] Peter |
|
|
Hi Peter, Thanks for the information about this, seems we had things setup differently. I've gone ahead with your suggestion, so let me know how the next nightly build goes. -Jason Fauchelle |
|
|
Hi Jason, I downloaded the latest nightly build today, and it solved my problem. Thanks Peter |
|