Help with Recursive Function - Building an Ordered LIst

R

Ryan Ternier

I have a section of my project that is Driving me nuts.

No one has been able to help that much on it, so i thought of posting it
here in hopes someone could help.

I need to print out an Ordered list.

Ex.

1. Something
2. Something Else
......A. SOmething
......B. Something
3. HEre's three
......A. Again
...........a. and again
4. Yo
...........a. zoom in some
5. This is 5


I have 2 DataTables. One DataTable has the Headings (which you see in the
above example) and the Indent of the heading. I don't use Child / parent
because it needs to be more flexible than that as you see with
4............a. The other DataTable has a bunch of items that goes under
each heading. I don't need to worry about that right now. I just need a way
of creating that ordered list from the DataTable that has the Heading Name
and Indent. (The headings are in order already when retrieved from the
DataBase.

The Indent is an Integer, and then I use the users settings to know how far
over to throw it (in pixels).

I was thinking a recursive loop, but I've only done those in University and
with very simple data. This is a bit more robust.

If anyone can help or point me in the right direction it would be awesome!

Thanks.

/RT
 
B

Bruce Wood

I just need a way of creating that ordered list from the DataTable that has the Heading
Name and Indent. (The headings are in order already when retrieved from the DataBase.)

OK, maybe I'm just being thick, but don't you already have what you
want? The headings are already in order when you retrieve them, but you
need to order them? Help me out here... there's obviously something I'm
missing....
 
O

Ollie Riches

further to what bruce has said why do you need a recursive method, why not
just a simple loop over the data table(s)

HTH

Ollie Riches
 
R

Ryan Ternier

Bruce,

yes the headings are in order that they need to appear. The issue I'm having
is puttint that order into an Ordered list.

The headings might be:

1
2
3
4
5

But I need:

1
......A
......B.
2
............a

Depending on the Indent of the headings.
 
R

Ryan Ternier

Recursion seemed the most elegant and efficient way of coding it.

Currently I have 2 for loops that output the data, but I don't have any
numbering (the ordered list numbering) in the document.

My Current Code is:

using(objPDF = new PDFObject(80,50,500,700))
{
//Are we printing attachments?
ShowAttachments = Attachments.Rows.Count > 0 ? true : false;
foreach(DataRow row in Sections.Rows)
{
objPDF.AddSection(Int32.Parse(row["Indent"].ToString()), row["Name"] !=
System.DBNull.Value ? row["Name"].ToString() : row["OtherText"].ToString(),
row["Description"].ToString());
//Loop throuh each item and compair it's heading ID with the rows heading
ID
foreach(DataRow r in Items.Rows)
{
//If the heading ID of the ITem is the same as the current heading
//Throw that item to the list
if(r["HeadingID"].ToString() == row["HeadingID"].ToString())
{
objPDF.AddItem(Utilities.DBToInteger(row["Indent"]),Utilities.DBToString(r["Description"]),Utilities.DBToString(r["AdditionalComments"]),Utilities.DBToString(r["ANotherCOlumnThatHasText"]),Utilities.DBToInteger(r["ItemID"]));
}
}
}
}


This is a generic function that loops through 2 DataTables. It grabs the
indent, but I don't know how to make the ordered list out of it.
A recursive loop might not be the best, but to me, it made sense. If theres
a better / another way of doing it, i'm all ears.
Thanks,
/RT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top