Enum Replacement Character


Author
Message
Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K

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.

Steve L. Taylor
Steve L. Taylor
StrataFrame Developer (68 reputation)
Group: StrataFrame Developers
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 Smile)

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. 

Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
Very cool Cool Somehow I missed that one. Thanks!
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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?
Steve L. Taylor
Steve L. Taylor
StrataFrame Developer (68 reputation)
Group: StrataFrame Developers
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.  BigGrin

I assume this is available in 1.5.1?

Good assumption.

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
...

Tongue

Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
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

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.

Chan
Chan
Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

How could I preserve the order of my enum list (may be by its value instead of alphabetic order)?



Thank you
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
If you are loading the enum into a combo, then you can either turn off the Sorted property so it will be in natural order, or you can change the sort to go by the value rather than the text.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search