Solved

List Question

Posted on 2013-06-25
6
207 Views
Last Modified: 2013-06-25
I have a c# (.net 4.5) windows application. I want to build a list of menu settings (see items below) that I will loop through to build menus.

What is the best way to store this in 4.5? There are so many other ways to store lists now, but they all seem to be geared towards storing just an identifier & a value or they require some convoluted way to store additional data.

The items I need to store for each menu is:
•      MenuGroup
•      MenuName
•      DisplayOrder
•      MenuLink
•      MenuIcon
•      MenuForeColor
•      MenuBGColor
0
Comment
Question by:Lensolo
  • 2
  • 2
  • 2
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Why not create a class that encompasses those items listed above? Then create a list of this new class?

e.g.

public class MenuDetails
{
	public string MenuGroup { get; set; }
	public string MenuName { get; set; }
	public int DisplayOrder { get; set; }
	public string MenuLink { get; set; }
	public Image MenuIcon { get; set; }
	public Color MenuForeColor { get; set; }
	public Color MenuBGColor { get; set; }
}

Open in new window


List<MenuDetails> menuList = new List<MenuDetails>();

Open in new window

0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>or they require some convoluted way to store additional data.

Create a class with the data you require.  Now create a generic List<xxx> of your classes.
0
 

Author Comment

by:Lensolo
Comment Utility
I think this might work. How do I set the values? This doesn't work. I haven't messed with custom classes yet. I'm new to c#.

 List<MenuItems> MenuList = new List<MenuItems>();
 MenuList.Add("Group1", "Menu Item", 1, "Link", "Icon", "Forecolor", "Background");
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
You need to create new instances of the class; then add these instances to the list.

List<MenuItems> MenuList = new List<MenuItems>();
MenuItems item = new MenuItems()
{
    MenuGroup = "Group1",
    MenuName = "Menu Item",
    DisplayOrder = 1,
    MenuLink = "Link",
    MenuIcon = "Icon",
    MenuForeColor = "Forecolor",
    MenuBGColor = "Background",
};

 MenuList.Add(item);

Open in new window

0
 

Author Closing Comment

by:Lensolo
Comment Utility
Thanks for taking the extra step. This was just what I was looking for.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Next - if you want sub menus as well as just plain menu items you can just expand the above.  Think about how - you actually have the answer.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now