Define String ENUM in VB.Net

后端 未结 6 1607
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 15:37

I am using Window Application for my project. There is situation where i need to define string enum and using it in my project.

i.e.

Dim PersonalInfo         


        
6条回答
  •  难免孤独
    2020-12-09 16:11

    If all you want to do is display the enums in a list or combo, you can use tagging such as

    Private Enum MyEnum
        Select_an_option___
        __ACCOUNTS__
        Invoices0
        Review_Invoice
        __MEETINGS__
        Scheduled_Meetings0
        Open_Meeting
        Cancelled_Meetings0
        Current_Meetings0
    End Enum
    

    Then pull the MyEnum into a string and use Replace (or Regex) to replace the tags: "___" with "...", "__" with "**", "_" with " ", and remove trailing numbers. Then repack it up into an array and dump it into a combobox which will look like:

    Select an option...
    **ACCOUNTS**
    Invoices
    Review Invoice
    **MEETINGS**
    Scheduled Meetings
    Open Meeting
    Cancelled Meetings
    Current Meetings
    

    (You can use the numbers to, say, disable a text field for inputting an invoice number or meeting room. In the example, Review Invoice and Open Meeting might be expecting additional input so a text box might be enabled for those selections.)

    When you parse the selected combo item, the enumeration will work as expected but you only really need to add a single line of code - the text replacement - to get the combo to look as you wish.

    (The explanation is about 10 times as involved as the actual solution!)

提交回复
热议问题