StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Enum Replacement CharacterExpand / Collapse
Author
Message
Posted 01/12/2007 10:51:20 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 1:32:21 PM
Posts: 368, Visits: 1,854

While the EnumSeparatePascalCase handles many situations it would be nice to be able to specify a substitution character like an underscore that could be used to insert spaces when displaying a enum. For example in our organization all departments are represented by a three character abbreviation and I have an enum that looks like:

 

Public Enum UserType

    HRA_Employee  

    HSA_Employee  

    Other_County_Employee  

    Community_Partner  

    Contractor  

    Vendor  

End Enum

 

Since I can’t separate all of them on PascalCase I end up inserting underscores. This works but it would make the application cleaner if I could easily eliminate the underscores when displaying the information.

Post #5780
Posted 01/12/2007 11:35:12 AM
StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 01/15/2008 8:44:34 AM
Posts: 40, Visits: 91
You can use the new EnumDisplayValueAttribute that we added just for this reason.  You just put the attributes on your enum values and when you build a combo box from the enum, you can just leave the EnumSeparatePascalCase values as their defaults and the enum's display values will be replaced with whatever you put in the string.

Public Enum MyEnum
    <MicroFour.StrataFrame.Tools.EnumDisplayValue("My Value #1")> _
    MyValue1

    <MicroFour.StrataFrame.Tools.EnumDisplayValue("My Value #2")> _
    MyValue2
End Enum

And since you're a C# guy (I think )

public enum MyEnum
{
    [MicroFour.StrataFrame.Tools.EnumDisplayValue("My Value #1")]
    MyValue1
}

You can also pass a second value to the attribute constructor that tells it that the first value is a localization key rather than a literal string for replacement. 

Post #5781
Posted 01/12/2007 1:32:55 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 1:32:21 PM
Posts: 368, Visits: 1,854
Very cool Somehow I missed that one. Thanks!
Post #5784
Posted 01/14/2007 4:06:35 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 4:08:06 PM
Posts: 1,323, Visits: 3,452
This is why I try to read every forum post....you never know what amazing little tidbit you'll find. This is very cool. It is documented yet? I assume this is available in 1.5.1?
Post #5806
Posted 01/15/2007 10:49:19 AM
StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 01/15/2008 8:44:34 AM
Posts: 40, Visits: 91
It is documented yet?

Kinda - it is in the "What's New in Version 1.5" .  I guess it was not enough of a hint.  We added the feature in order to localize enums -- those darn Brazilians. 

I assume this is available in 1.5.1?

Good assumption.

Post #5824
Posted 01/15/2007 12:04:28 PM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 8:41:37 PM
Posts: 798, Visits: 11,595
...

Post #5835
Posted 01/19/2007 3:01:50 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 1:32:21 PM
Posts: 368, Visits: 1,854
Any plans on adding this capability to the situation where an enum is bound to a text box control? Right now the "unformatted" enum is displayed.

-Larry

Post #5970
Posted 01/19/2007 3:13:48 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 10/21/2008 9:20:58 AM
Posts: 2,685, Visits: 1,887
Not right now.  You could, however, accomplish this by creating your own EnumTextBox subclass and within the constructor, add a handler to the this.DataBindings.CollectionChanged event.  Within this event, add a handler to the binding object's Format event.  Within the format handler, call the MicroFour.StrataFrame.Tools.Common.GetEnumDisplayValue() method and change the event args.  This will allow you to format the data going to the control.

If you want to allow the text box to be editable, then you'll also need to handle the Parse event of the binding object to reverse the process of the format event handler.


www.bungie.net
Post #5973
Posted 01/20/2007 9:47:41 AM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 7:07:00 AM
Posts: 462, Visits: 1,722
Hi,
How could I preserve the order of my enum list (may be by its value instead of alphabetic order)?

Thank you
Post #5993