2 Replies - 393 Views - Last Post: 20 July 2013 - 07:26 AM Rate Topic: -----

#1 GUYGLK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-July 13

Name property for List

Posted 19 July 2013 - 11:44 PM

hi there,
c# wpf

i was wondering, can a list<T> have a name property?
why do i ask?
well, i have about 12 lists created programmaticaly (all of which are public static lists of string type).
what i want to do is load all of there NAMES into a combocbox (and by NAME i mean an interface name (for the user to see, insted of the raw instance name of a list)

for example:
public static List<string> AllItemsList = new List<string();
public static List<string> LabelsList= new List<string();
public static List<string> AuthorsList= new List<string();



Insted of adding them like this into a combobox (using hard coded strings):
CheckBox1.Items.Add("All Items")
CheckBox1.Items.Add("Labels")
CheckBox1.Items.Add("Authors")



I want something more like this (:
CheckBox1.Items.Add(AllItemsList.Name)
CheckBox1.Items.Add(LabelsList.Name)
CheckBox1.Items.Add(AuthorsList.Name)



is it bossible?
i don't have any idea where to start...

thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Name property for List

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Name property for List

Posted 20 July 2013 - 02:16 AM

Since List<T> isn't a sealed class, you can derive your own class from it and add a Name property.
Was This Post Helpful? 0
  • +
  • -

#3 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Name property for List

Posted 20 July 2013 - 07:26 AM

As Momerath said, you can derive your own list, but you could also use the Tag property of the list and set that as the name. Momerath's suggestion would be more apparent to someone besides you who might be reading the code though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1