Need to fill listbox control with enumeration from subroutine.

  • Thread starter Thread starter Noel Justus
  • Start date Start date
N

Noel Justus

Simply wish to create a generic subroutine which would fill a listbox
control with the contents of an enumeration in this fashion:

FillListBox(Listbox1,TabAlignment)
FillListBox(Listbox2,Appearance)


Public Sub FillListBox(ByVal lstBox As ListBox, ByVal xEnum As
[Enum])
....
....
End Sub

The problem is that I cannot find a reference to all the enumerated
values when
using a subroutine.
I am able to use [Enum].Getnames and [Enum].parse to fill the box but
I must use the enumeration type specifically....and not a reference to
it.

Any help filling in the subroutine would be appreciated.
 
Hello,

Thanks for your post. You should convert Enum as Type object, and then use
System.Reflection to get the fields of the Enum in the subroutine. Please
refer to the following code snippet:

'----------------------code snippet------------------------
FillListBox(Listbox1, GetType(TabAlignment))

Public Sub FillListBox(ByVal lstBox As ListBox, ByVal xEnum As Type)
For Each enumField As System.Reflection.FieldInfo In xEnum.GetFields
If enumField.IsStatic Then
' Fill the listbox with enumField.Name
End If
Next
End Sub
'------------------------------------end----------------------

Please check it on your side.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top