简体   繁体   中英

How to store an enum inside a DataColum of a DataTable and show localized text in .Net

I have to store on one DataColum of one DataTable an Enum containing some values. The enum is defined as follow:

Imports System.ComponentModel
Imports System.Globalization

Public Enum FirmwareUpdateStatus
    <Description("updateNotExecuted")> UpdateNotExecuted = 0
    <Description("updateSuccess")> UpdateSuccess = 1
    <Description("updateError")> UpdateError = 2
End Enum

I have also a class called Enum2 that has a method called GetDescription that returns the localized text of an enum value. What I want to do is to show this text into the grid that shows the DataTable but storing the enum value, not the string.

As no one posted a solution I had to work out one by myself, maybe not the best one but it works.

What I did is to use two DataColumns, one for storing and consulting the enum value and another one for the text displayed to the user. The enum DataColum is not set to be shown at the UI grid and that's all.

Thanks anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM