I am looking to create a report of menu items. Here’s a simplified example of my data that I already have in a IList collection:
0 1 0 N
1 1 1 N
1 1 2 Y
0 2 1 N
1 2 2 N
1 2 3 Y
1 2 4 N
Where
Column 1 - row type ( 0 = top level, 1 = sub level)
Column 2 - top level menu
Column 3 - sub level menu
Column 4 - default ( Y = Yes, N = No)
What I need to do is to create headings such as /1-2 etc. Here the example shows the heading I need to create for this small set of data.
/1-2
/1-1
/1-2
/2-3
/2-2
/2-3
/2-4
The heading is calculated as follows.
- For each row that’s a top level the heading is “/” + column1 + X.
Where X is calculated by looking ahead to find which following sub level for that heading has a Y in the default column. - For each row that’s a sub level the heading is “/” + column1 + column2
Sorry if my explanation is not good. It’s not easy to explain.
Can anyone give me a suggestion about how I could implement the look ahead that is needed when I create a row that’s of a type “top level”?
I would suggest parsing the input data into a tree based structure, and then converting that tree based structure into your desired output rather than trying to directly map one to the other. This is particularly true if the input rows aren’t always in order and with perfectly valid values.