ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > Word Index > Generating an Index In Code

Generating an Index In Code

Typically, the following steps would be involved in providing a simple one-level index in a document that is created in code:

1.   An instance of the RenderIndex class should be created and stored in a local variable (as noted above, the index may not precede the occurrences of its entries).

2.   As content (render objects) is added to the document, some program logic should identify strings that are to become entries (terms) in the index. Each such string should be tested on whether it has already been added to the Entries collection of the index object created in step 1. If this is a new entry, a new IndexEntry object should be created for it, and added to the index.

3.   An entry occurrence (IndexEntryOccurrence) should be added to the existing or newly created entry, to point to the location of the occurrence in the document. Usually the location would be identified by the RenderObject that contains it and is being added to the document.

4.   When all occurrences of the entries have been added to the document, the RenderIndex object created in step 1 can be added to the document's body.

5.   When the document is generated, the RenderIndex object produces a hyperlinked index of the entries that have been added to it. The entries are automatically sorted, split into groups corresponding to each letter, and letter headings added.

Of course, this is only one simple possible scenario designed to demonstrate the relationship between the main objects involved in creating an index. Other possibilities include the creation of indexed terms (index entries) prior to document creation (for example, based on an external dictionary of terms), adding nested entries (sub-entries), and so on.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.