Chris Zwirlein

Hi!

I'm searching for a hint... I created a DataSet from a Database Query which looks like:

ITEM_NAME LVL

File 1

Save 2

Create 2

Create New 3

Create Specific 3

Quit 2

My Problem is to make a DropDown Menu out of this using a ToolStripMenuItem. The LVL number is to specify the parent and child items. Does anyone have a suggestion

Thanks,

Chris

P.S. I'm a beginner, which means that I'm currently learning C#



Re: Windows Forms General Creating Menu from DataSet??

Alan Jackson

From the list you've given, it looks like you also have some form of ordering that you want to maintain in your menu.

I would suggest that you add to be the order in which you want them to appear within that level. I would also suggest that you add the concept of the parent that you want the children to be attached to, which means you will need to add an ID to each row as well. This would then produce you a result set something like

ID ITEM_NAME LVL PARENT_ID

1 File 1 Null

2 Save 2 1

3 Create 2 1

4 Create New 3 3

etc

If you feel more brave with this idea, you can actually drop the level as this is actually redundant.

You then have two choices as to how to process the menu items to build up the menu structure you want.

1) you could recursively call over the result set to build the menu structure that you desire (requires a single pass over the result set, but you need to be aware of possible infinite recursion)

2) Build all the menu items and then sort out their parentage (requires 2 passes over the result set, plus storing all the menu items in a temporary array while processing)

I'm sure others will come up with different solutions to this, but hopefully this might get you started.






Re: Windows Forms General Creating Menu from DataSet??

Chris Zwirlein

Hi Alan!

Thank you for this different point of view.

The ID for the items is not necessary because the items are already in the right order.

One item's parent is e.g. "Create" which has LVL 2 an the child items are "Create New" (LVL 3) and so on.

I think I'll need something that checks the actual level and the last given level and if the last given level has a lower number it will append the items to it

Any idea how to create the right array and store the items into it