473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with Recursive Function - Building an Ordered LIst

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

Nov 17 '05 #1
4 6474
> 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....

Nov 17 '05 #2
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

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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....

Nov 17 '05 #3
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.

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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....

Nov 17 '05 #4
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

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
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

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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....


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin | last post by:
hi everyone. i'm trying to write asp to build an ordered list from a database table. i'm running into issues with place holding. here's an example of the data from the table.. id | parentID...
2
by: Ryan Ternier | last post by:
I'm currently run into a snag on one of my projects. We need to create an ordered list (Mutli levels). Ie: 1. Some Title ....A....Something here ....B....Something Else 2. Another Title
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
14
by: Fabian Steiner | last post by:
Hello! I have got a Python "Device" Object which has got a attribute (list) called children which my contain several other "Device" objects. I implemented it this way in order to achieve a kind...
1
by: none | last post by:
I'm trying to create a recursive function to evaluate the expressions within a list. The function uses eval() to evaluate the list. Like a lisp interpreter but very limited. What I'm looking for...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
4
by: rumbylove | last post by:
Could I please have the solutions to the following problems 1. (4 points) Your friend has to write code to make sure that the parentheses in an arithmetic expression are balanced, i.e. for every...
1
by: skanemupp | last post by:
the 0.409 vs 0.095 is the total times right? so the imperative function is >4 times faster than the recursive. or what does tottime stand for? is this always the case that the recursive function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.