|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Referencing an Enum with Embedded SpacesI created an Enum with the EnumBuilder which allows you to add items with spaces embedded as well as the name of the Enum. e.g. US States and a member of New York
The normal way you would iterate through an Enum is as follows For Each lstrItem As String In [Enum].GetNames(GetType(Geographical.US_States)) Me.Combo.Items.Add(lstrItem) Next But how would you reference an Enum of "US States" ??? * Iknow I could just as easily create an Enum US_States... just a question though !!! You don't. Even if the VB.NET syntax allows this, it would be extremely
confusing to programmers attempting to use or modify your Enum. Mike Ober. "Desmond Cassidy" <Desmond.Cass***@T-Online.de> wrote in message I created an Enum with the EnumBuilder which allows you to add items withnews:eKIkgVP1GHA.3752@TK2MSFTNGP02.phx.gbl... spaces embedded as well as the name of the Enum. e.g. US States and a member of New York The normal way you would iterate through an Enum is as follows For Each lstrItem As String In [Enum].GetNames(GetType(Geographical.US_States)) Me.Combo.Items.Add(lstrItem) Next But how would you reference an Enum of "US States" ??? * Iknow I could just as easily create an Enum US_States... just a question though !!! "Desmond Cassidy" <Desmond.Cass***@T-Online.de> schrieb: I'd choose a different approach:>I created an Enum with the EnumBuilder which allows you to add items with >spaces embedded as well as the name of the Enum. e.g. US States and a >member of New York > >The normal way you would iterate through an Enum is as follows >For Each lstrItem As String In >[Enum].GetNames(GetType(Geographical.US_States)) > Me.Combo.Items.Add(lstrItem) >Next > >But how would you reference an Enum of "US States" ??? * Iknow I could just >as easily create an Enum US_States... Adding descriptions to enumeration constants <URL:http://dotnet.mvps.org/dotnet/faqs/?id=enumdescription&lang=en> Creating enumerations of items with a certain arbitrary data type <URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en> Article in German: <URL:http://dotnet.mvps.org/dotnet/articles/enums/> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Absolutely excellent approach - Vielen Dank Herfried
Mike: The point was that I wanted to make the enum full data e.g. "New York" , available for the combobox but not necessarily having the programmer accessing it - the approach in Herfried suggestion is spot on !! Many thanks, Desmond. Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:%23sE%23OJS1GHA.4228@TK2MSFTNGP06.phx.gbl... > "Desmond Cassidy" <Desmond.Cass***@T-Online.de> schrieb: >>I created an Enum with the EnumBuilder which allows you to add items with >>spaces embedded as well as the name of the Enum. e.g. US States and a >>member of New York >> >>The normal way you would iterate through an Enum is as follows >>For Each lstrItem As String In >>[Enum].GetNames(GetType(Geographical.US_States)) >> Me.Combo.Items.Add(lstrItem) >>Next >> >>But how would you reference an Enum of "US States" ??? * Iknow I could >>just as easily create an Enum US_States... > > I'd choose a different approach: > > Adding descriptions to enumeration constants > <URL:http://dotnet.mvps.org/dotnet/faqs/?id=enumdescription&lang=en> > > Creating enumerations of items with a certain arbitrary data type > <URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en> > > Article in German: > > <URL:http://dotnet.mvps.org/dotnet/articles/enums/> > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> > |
|||||||||||||||||||||||