Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumeration

Status
Not open for further replies.

MsMope

IS-IT--Management
Sep 3, 2003
83
US
Good Morning,
I have an enumerations declared in a common class written in C# (company.common) I want to dispaly the members of this enumeration in my comboBox(cboCategories). Any Ideas?

Private mBuilderNote As New WausauHomes.BuilderProfile.whws.wausauhomes.com.builderservices.NoteTypes

 
there is a c# forum for this
and otherwise we or they would need more information.

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
If you want the Name for the value.
Dim objType As Type = obj.GetType
If objType.IsEnum Then
Dim eName As String = [Enum].GetName(objType, obj)
If eName Is Nothing Then
writer.WriteString(obj.ToString)
Else
writer.WriteString(eName)
End If
End If

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
The default behavior of an enumeration's ToString implementation (which is what's called when a listbox wants to display something) is to show the name of the item (what you want).

Once the user has selected something, to go from there back to your enumeration, you use the static/shared Parse method:

C#:
Code:
MyEnumType TheEnumValue = (MyEnumType)Enum.Parse(typeof(MyEnumType), ListBox.SelectedItem);

VB.NET:
Code:
Dim TheEnumValue As MyEnumType = CType([Enum].Parse(GetType(MyEnumType), MyListBox.SelectedItem), MyEnumType)

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top