Shared Function EnumToDataTable(ByVal typEnum As Type) As DataTable
Dim ddlTypnames() As String = [Enum].GetNames(typEnum)
Dim arrddlTypVals As Array = [Enum].GetValues(typEnum)
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("values", GetType(Int32)))
dt.Columns.Add(New DataColumn("names", GetType(String)))
Dim i2 As Integer
For i2 = 0 To ddlTypnames.Length() - 1
dr = dt.NewRow()
dr(0) = CInt(arrddlTypVals(i2))
dr(1) = ddlTypnames(i2)
dt.Rows.Add(dr)
Next i2
Return dt
End Function
Using this function
Dim dt As DataTable
dt = EnumToDataTable(GetType(EnumSample))
Happy Coding!
No comments:
Post a Comment