Aspose::Words::Lists::ListCollection Class Reference

Detailed Description

Stores and manages formatting of bulleted and numbered lists used in a document.

A list in a Microsoft Word document is a set of list formatting properties. The formatting of the lists is stored in the ListCollection collection separately from the paragraphs of text.

You do not create objects of this class. There is always only one ListCollection object per document and it is accessible via the Lists property.

To create a new list based on a predefined list template or based on a list style, use the Add() method.

To create a new list with formatting identical to an existing list, use the AddCopy() method.

To make a paragraph bulleted or numbered, you need to apply list formatting to a paragraph by assigning a List object to the List property of ListFormat.

To remove list formatting from a paragraph, use the RemoveNumbers method.

If you know a bit about WordprocessingML, then you might know it defines separate concepts for "list" and "list definition". This exactly corresponds to how list formatting is stored in a Microsoft Word document at the low level. List definition is like a "schema" and list is like an instance of a list definition.

To simplify programming model, Aspose.Words hides the distinction between list and list definition in much the same way like Microsoft Word hides this in its user interface. This allows you to concentrate more on how you want your document to look like, rather than building low-level objects to satisfy requirements of the Microsoft Word file format.

It is not possible to delete lists once they are created in the current version of Aspose.Words. This is similar to Microsoft Word where user does not have explicit control over list definitions.

See also
Aspose::Words::Lists::List
Aspose::Words::Lists::ListLevel
Aspose::Words::Lists::ListFormat
Examples

Shows how to work with list levels.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
ASSERT_FALSE(builder->get_ListFormat()->get_IsListItem());
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Below are two types of lists that we can create using a document builder.
// 1 - A numbered list:
// Numbered lists create a logical order for their paragraphs by numbering each item.
builder->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::NumberDefault));
ASSERT_TRUE(builder->get_ListFormat()->get_IsListItem());
// By setting the "ListLevelNumber" property, we can increase the list level
// to begin a self-contained sub-list at the current list item.
// The Microsoft Word list template called "NumberDefault" uses numbers to create list levels for the first list level.
// Deeper list levels use letters and lowercase Roman numerals.
for (int i = 0; i < 9; i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
// 2 - A bulleted list:
// This list will apply an indent and a bullet symbol ("•") before each paragraph.
// Deeper levels of this list will use different symbols, such as "■" and "○".
builder->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
for (int i = 0; i < 9; i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
// We can disable list formatting to not format any subsequent paragraphs as lists by un-setting the "List" flag.
builder->get_ListFormat()->set_List(nullptr);
ASSERT_FALSE(builder->get_ListFormat()->get_IsListItem());
doc->Save(ArtifactsDir + u"Lists.SpecifyListLevel.docx");

Shows how to restart numbering in a list by copying a list.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Create a list from a Microsoft Word template, and customize its first list level.
SharedPtr<List> list1 = doc->get_Lists()->Add(ListTemplate::NumberArabicParenthesis);
list1->get_ListLevels()->idx_get(0)->get_Font()->set_Color(System::Drawing::Color::get_Red());
list1->get_ListLevels()->idx_get(0)->set_Alignment(ListLevelAlignment::Right);
// Apply our list to some paragraphs.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"List 1 starts below:");
builder->get_ListFormat()->set_List(list1);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
// We can add a copy of an existing list to the document's list collection
// to create a similar list without making changes to the original.
SharedPtr<List> list2 = doc->get_Lists()->AddCopy(list1);
list2->get_ListLevels()->idx_get(0)->get_Font()->set_Color(System::Drawing::Color::get_Blue());
list2->get_ListLevels()->idx_get(0)->set_StartAt(10);
// Apply the second list to new paragraphs.
builder->Writeln(u"List 2 starts below:");
builder->get_ListFormat()->set_List(list2);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
doc->Save(ArtifactsDir + u"Lists.RestartNumberingUsingListCopy.docx");

Shows how to create a document with a sample of all the lists from another document.

void PrintOutAllLists()
{
auto srcDoc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto dstDoc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(dstDoc);
for (const auto& srcList : srcDoc->get_Lists())
{
SharedPtr<List> dstList = dstDoc->get_Lists()->AddCopy(srcList);
AddListSample(builder, dstList);
}
dstDoc->Save(ArtifactsDir + u"Lists.PrintOutAllLists.docx");
}
static void AddListSample(SharedPtr<DocumentBuilder> builder, SharedPtr<List> list)
{
builder->Writeln(String(u"Sample formatting of list with ListId:") + list->get_ListId());
builder->get_ListFormat()->set_List(list);
for (int i = 0; i < list->get_ListLevels()->get_Count(); i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
builder->get_ListFormat()->RemoveNumbers();
builder->Writeln();
}

#include <Aspose.Words.Cpp/Lists/ListCollection.h>

+ Inheritance diagram for Aspose::Words::Lists::ListCollection:

Public Types

using const_iterator = typename const_iterator
 
using iterator = typename iterator
 
using iterator_holder_type = List< SharedPtr< List > >
 

Public Member Functions

SharedPtr< ListAdd (ListTemplate listTemplate)
 Creates a new list based on a predefined template and adds it to the collection of lists in the document. More...
 
SharedPtr< ListAdd (const SharedPtr< Style > &listStyle)
 Creates a new list that references a list style and adds it to the collection of lists in the document. More...
 
SharedPtr< ListAddCopy (const SharedPtr< List > &srcList)
 Creates a new list by copying the specified list and adding it to the collection of lists in the document. More...
 
const_iterator begin () const noexcept
 
iterator begin () noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
const_iterator end () const noexcept
 
iterator end () noexcept
 
int32_t get_Count ()
 Gets the count of numbered and bulleted lists in the document. More...
 
SharedPtr< DocumentBaseget_Document () const
 Gets the owner document. More...
 
SharedPtr< IEnumerator< SharedPtr< List > > > GetEnumerator () override
 Gets the enumerator object that will enumerate lists in the document. More...
 
SharedPtr< ListGetListByListId (int32_t listId)
 Gets a list by a list identifier. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< Listidx_get (int32_t index)
 Gets a list by index. More...
 
virtual bool Is (const TypeInfo &target) const override
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Typedef Documentation

◆ const_iterator

◆ iterator

◆ iterator_holder_type

Member Function Documentation

◆ Add() [1/2]

System::SharedPtr<Aspose::Words::Lists::List> Aspose::Words::Lists::ListCollection::Add ( Aspose::Words::Lists::ListTemplate  listTemplate)

Creates a new list based on a predefined template and adds it to the collection of lists in the document.

Aspose.Words list templates correspond to the 21 list templates available in the Bullets and Numbering dialog box in Microsoft Word 2003.

All lists created using this method have 9 list levels.

Parameters
listTemplateThe template of the list.
Returns
The newly created list.
Examples

Shows how to work with list levels.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
ASSERT_FALSE(builder->get_ListFormat()->get_IsListItem());
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Below are two types of lists that we can create using a document builder.
// 1 - A numbered list:
// Numbered lists create a logical order for their paragraphs by numbering each item.
builder->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::NumberDefault));
ASSERT_TRUE(builder->get_ListFormat()->get_IsListItem());
// By setting the "ListLevelNumber" property, we can increase the list level
// to begin a self-contained sub-list at the current list item.
// The Microsoft Word list template called "NumberDefault" uses numbers to create list levels for the first list level.
// Deeper list levels use letters and lowercase Roman numerals.
for (int i = 0; i < 9; i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
// 2 - A bulleted list:
// This list will apply an indent and a bullet symbol ("•") before each paragraph.
// Deeper levels of this list will use different symbols, such as "■" and "○".
builder->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
for (int i = 0; i < 9; i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
// We can disable list formatting to not format any subsequent paragraphs as lists by un-setting the "List" flag.
builder->get_ListFormat()->set_List(nullptr);
ASSERT_FALSE(builder->get_ListFormat()->get_IsListItem());
doc->Save(ArtifactsDir + u"Lists.SpecifyListLevel.docx");

Shows how to restart numbering in a list by copying a list.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Create a list from a Microsoft Word template, and customize its first list level.
SharedPtr<List> list1 = doc->get_Lists()->Add(ListTemplate::NumberArabicParenthesis);
list1->get_ListLevels()->idx_get(0)->get_Font()->set_Color(System::Drawing::Color::get_Red());
list1->get_ListLevels()->idx_get(0)->set_Alignment(ListLevelAlignment::Right);
// Apply our list to some paragraphs.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"List 1 starts below:");
builder->get_ListFormat()->set_List(list1);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
// We can add a copy of an existing list to the document's list collection
// to create a similar list without making changes to the original.
SharedPtr<List> list2 = doc->get_Lists()->AddCopy(list1);
list2->get_ListLevels()->idx_get(0)->get_Font()->set_Color(System::Drawing::Color::get_Blue());
list2->get_ListLevels()->idx_get(0)->set_StartAt(10);
// Apply the second list to new paragraphs.
builder->Writeln(u"List 2 starts below:");
builder->get_ListFormat()->set_List(list2);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
doc->Save(ArtifactsDir + u"Lists.RestartNumberingUsingListCopy.docx");

Shows how to create a list by applying a new list format to a collection of paragraphs.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Paragraph 1");
builder->Writeln(u"Paragraph 2");
builder->Write(u"Paragraph 3");
SharedPtr<NodeCollection> paras = doc->GetChildNodes(NodeType::Paragraph, true);
ASSERT_EQ(0, paras->LINQ_Count([](SharedPtr<Node> n) { return System::DynamicCast<Paragraph>(n)->get_ListFormat()->get_IsListItem(); }));
SharedPtr<List> list = doc->get_Lists()->Add(ListTemplate::NumberUppercaseLetterDot);
for (const auto& paragraph : System::IterateOver(paras->LINQ_OfType<SharedPtr<Paragraph>>()))
{
paragraph->get_ListFormat()->set_List(list);
paragraph->get_ListFormat()->set_ListLevelNumber(1);
}
ASSERT_EQ(3, paras->LINQ_Count([](SharedPtr<Node> n) { return System::DynamicCast<Paragraph>(n)->get_ListFormat()->get_IsListItem(); }));

◆ Add() [2/2]

System::SharedPtr<Aspose::Words::Lists::List> Aspose::Words::Lists::ListCollection::Add ( const System::SharedPtr< Aspose::Words::Style > &  listStyle)

Creates a new list that references a list style and adds it to the collection of lists in the document.

The newly created list references the list style. If you change the properties of the list style, it is reflected in the properties of the list. Vice versa, if you change the properties of the list, it is reflected in the properties of the list style.

Parameters
listStyleThe list style.
Returns
The newly created list.
Examples

Shows how to create a list style and use it in a document.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// We can contain an entire List object within a style.
SharedPtr<Style> listStyle = doc->get_Styles()->Add(StyleType::List, u"MyListStyle");
SharedPtr<List> list1 = listStyle->get_List();
ASSERT_TRUE(list1->get_IsListStyleDefinition());
ASSERT_FALSE(list1->get_IsListStyleReference());
ASSERT_TRUE(list1->get_IsMultiLevel());
ASPOSE_ASSERT_EQ(listStyle, list1->get_Style());
// Change the appearance of all list levels in our list.
for (const auto& level : list1->get_ListLevels())
{
level->get_Font()->set_Name(u"Verdana");
level->get_Font()->set_Color(System::Drawing::Color::get_Blue());
level->get_Font()->set_Bold(true);
}
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Using list style first time:");
// Create another list from a list within a style.
SharedPtr<List> list2 = doc->get_Lists()->Add(listStyle);
ASSERT_FALSE(list2->get_IsListStyleDefinition());
ASSERT_TRUE(list2->get_IsListStyleReference());
ASPOSE_ASSERT_EQ(listStyle, list2->get_Style());
// Add some list items that our list will format.
builder->get_ListFormat()->set_List(list2);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
builder->Writeln(u"Using list style second time:");
// Create and apply another list based on the list style.
SharedPtr<List> list3 = doc->get_Lists()->Add(listStyle);
builder->get_ListFormat()->set_List(list3);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
builder->get_Document()->Save(ArtifactsDir + u"Lists.CreateAndUseListStyle.docx");

◆ AddCopy()

System::SharedPtr<Aspose::Words::Lists::List> Aspose::Words::Lists::ListCollection::AddCopy ( const System::SharedPtr< Aspose::Words::Lists::List > &  srcList)

Creates a new list by copying the specified list and adding it to the collection of lists in the document.

The source list can be from any document. If the source list belongs to a different document, a copy of the list is created and added to the current document.

If the source list is a reference to or a definition of a list style, the newly created list is not related to the original list style.

Parameters
srcListThe source list to copy from.
Returns
The newly created list.
Examples

Shows how to restart numbering in a list by copying a list.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Create a list from a Microsoft Word template, and customize its first list level.
SharedPtr<List> list1 = doc->get_Lists()->Add(ListTemplate::NumberArabicParenthesis);
list1->get_ListLevels()->idx_get(0)->get_Font()->set_Color(System::Drawing::Color::get_Red());
list1->get_ListLevels()->idx_get(0)->set_Alignment(ListLevelAlignment::Right);
// Apply our list to some paragraphs.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"List 1 starts below:");
builder->get_ListFormat()->set_List(list1);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
// We can add a copy of an existing list to the document's list collection
// to create a similar list without making changes to the original.
SharedPtr<List> list2 = doc->get_Lists()->AddCopy(list1);
list2->get_ListLevels()->idx_get(0)->get_Font()->set_Color(System::Drawing::Color::get_Blue());
list2->get_ListLevels()->idx_get(0)->set_StartAt(10);
// Apply the second list to new paragraphs.
builder->Writeln(u"List 2 starts below:");
builder->get_ListFormat()->set_List(list2);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
doc->Save(ArtifactsDir + u"Lists.RestartNumberingUsingListCopy.docx");

Shows how to create a document with a sample of all the lists from another document.

void PrintOutAllLists()
{
auto srcDoc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto dstDoc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(dstDoc);
for (const auto& srcList : srcDoc->get_Lists())
{
SharedPtr<List> dstList = dstDoc->get_Lists()->AddCopy(srcList);
AddListSample(builder, dstList);
}
dstDoc->Save(ArtifactsDir + u"Lists.PrintOutAllLists.docx");
}
static void AddListSample(SharedPtr<DocumentBuilder> builder, SharedPtr<List> list)
{
builder->Writeln(String(u"Sample formatting of list with ListId:") + list->get_ListId());
builder->get_ListFormat()->set_List(list);
for (int i = 0; i < list->get_ListLevels()->get_Count(); i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
builder->get_ListFormat()->RemoveNumbers();
builder->Writeln();
}

◆ begin() [1/2]

const_iterator Aspose::Words::Lists::ListCollection::begin ( ) const
noexcept

◆ begin() [2/2]

iterator Aspose::Words::Lists::ListCollection::begin ( )
noexcept

◆ cbegin()

const_iterator Aspose::Words::Lists::ListCollection::cbegin ( ) const
noexcept

◆ cend()

const_iterator Aspose::Words::Lists::ListCollection::cend ( ) const
noexcept

◆ end() [1/2]

const_iterator Aspose::Words::Lists::ListCollection::end ( ) const
noexcept

◆ end() [2/2]

iterator Aspose::Words::Lists::ListCollection::end ( )
noexcept

◆ get_Count()

int32_t Aspose::Words::Lists::ListCollection::get_Count ( )

Gets the count of numbered and bulleted lists in the document.

Examples

Shows how to verify owner document properties of lists.

auto doc = MakeObject<Document>();
SharedPtr<ListCollection> lists = doc->get_Lists();
ASPOSE_ASSERT_EQ(doc, lists->get_Document());
SharedPtr<List> list = lists->Add(ListTemplate::BulletDefault);
ASPOSE_ASSERT_EQ(doc, list->get_Document());
std::cout << (String(u"Current list count: ") + lists->get_Count()) << std::endl;
std::cout << (String(u"Is the first document list: ") + (System::ObjectExt::Equals(lists->idx_get(0), list))) << std::endl;
std::cout << (String(u"ListId: ") + list->get_ListId()) << std::endl;
std::cout << (String(u"List is the same by ListId: ") + (System::ObjectExt::Equals(lists->GetListByListId(1), list))) << std::endl;

◆ get_Document()

System::SharedPtr<Aspose::Words::DocumentBase> Aspose::Words::Lists::ListCollection::get_Document ( ) const

Gets the owner document.

Examples

Shows how to verify owner document properties of lists.

auto doc = MakeObject<Document>();
SharedPtr<ListCollection> lists = doc->get_Lists();
ASPOSE_ASSERT_EQ(doc, lists->get_Document());
SharedPtr<List> list = lists->Add(ListTemplate::BulletDefault);
ASPOSE_ASSERT_EQ(doc, list->get_Document());
std::cout << (String(u"Current list count: ") + lists->get_Count()) << std::endl;
std::cout << (String(u"Is the first document list: ") + (System::ObjectExt::Equals(lists->idx_get(0), list))) << std::endl;
std::cout << (String(u"ListId: ") + list->get_ListId()) << std::endl;
std::cout << (String(u"List is the same by ListId: ") + (System::ObjectExt::Equals(lists->GetListByListId(1), list))) << std::endl;

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Lists::List> > > Aspose::Words::Lists::ListCollection::GetEnumerator ( )
override

Gets the enumerator object that will enumerate lists in the document.

Examples

Shows how to create a document with a sample of all the lists from another document.

void PrintOutAllLists()
{
auto srcDoc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto dstDoc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(dstDoc);
for (const auto& srcList : srcDoc->get_Lists())
{
SharedPtr<List> dstList = dstDoc->get_Lists()->AddCopy(srcList);
AddListSample(builder, dstList);
}
dstDoc->Save(ArtifactsDir + u"Lists.PrintOutAllLists.docx");
}
static void AddListSample(SharedPtr<DocumentBuilder> builder, SharedPtr<List> list)
{
builder->Writeln(String(u"Sample formatting of list with ListId:") + list->get_ListId());
builder->get_ListFormat()->set_List(list);
for (int i = 0; i < list->get_ListLevels()->get_Count(); i++)
{
builder->get_ListFormat()->set_ListLevelNumber(i);
builder->Writeln(String(u"Level ") + i);
}
builder->get_ListFormat()->RemoveNumbers();
builder->Writeln();
}

◆ GetListByListId()

System::SharedPtr<Aspose::Words::Lists::List> Aspose::Words::Lists::ListCollection::GetListByListId ( int32_t  listId)

Gets a list by a list identifier.

You don't normally need to use this method. Most of the time you apply list formatting to paragraphs just by settings the List property of the ListFormat object.

Parameters
listIdThe list identifier.
Returns
Returns the list object. Returns null if a list with the specified identifier was not found.
Examples

Shows how to verify owner document properties of lists.

auto doc = MakeObject<Document>();
SharedPtr<ListCollection> lists = doc->get_Lists();
ASPOSE_ASSERT_EQ(doc, lists->get_Document());
SharedPtr<List> list = lists->Add(ListTemplate::BulletDefault);
ASPOSE_ASSERT_EQ(doc, list->get_Document());
std::cout << (String(u"Current list count: ") + lists->get_Count()) << std::endl;
std::cout << (String(u"Is the first document list: ") + (System::ObjectExt::Equals(lists->idx_get(0), list))) << std::endl;
std::cout << (String(u"ListId: ") + list->get_ListId()) << std::endl;
std::cout << (String(u"List is the same by ListId: ") + (System::ObjectExt::Equals(lists->GetListByListId(1), list))) << std::endl;

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Lists::ListCollection::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ idx_get()

System::SharedPtr<Aspose::Words::Lists::List> Aspose::Words::Lists::ListCollection::idx_get ( int32_t  index)

Gets a list by index.

Examples

Shows how to apply list formatting of an existing list to a collection of paragraphs.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Paragraph 1");
builder->Writeln(u"Paragraph 2");
builder->Write(u"Paragraph 3");
SharedPtr<NodeCollection> paras = doc->GetChildNodes(NodeType::Paragraph, true);
ASSERT_EQ(0, paras->LINQ_Count([](SharedPtr<Node> n) { return System::DynamicCast<Paragraph>(n)->get_ListFormat()->get_IsListItem(); }));
doc->get_Lists()->Add(ListTemplate::NumberDefault);
SharedPtr<List> list = doc->get_Lists()->idx_get(0);
for (const auto& paragraph : System::IterateOver(paras->LINQ_OfType<SharedPtr<Paragraph>>()))
{
paragraph->get_ListFormat()->set_List(list);
paragraph->get_ListFormat()->set_ListLevelNumber(2);
}
ASSERT_EQ(3, paras->LINQ_Count([](SharedPtr<Node> n) { return System::DynamicCast<Paragraph>(n)->get_ListFormat()->get_IsListItem(); }));

Shows how to verify owner document properties of lists.

auto doc = MakeObject<Document>();
SharedPtr<ListCollection> lists = doc->get_Lists();
ASPOSE_ASSERT_EQ(doc, lists->get_Document());
SharedPtr<List> list = lists->Add(ListTemplate::BulletDefault);
ASPOSE_ASSERT_EQ(doc, list->get_Document());
std::cout << (String(u"Current list count: ") + lists->get_Count()) << std::endl;
std::cout << (String(u"Is the first document list: ") + (System::ObjectExt::Equals(lists->idx_get(0), list))) << std::endl;
std::cout << (String(u"ListId: ") + list->get_ListId()) << std::endl;
std::cout << (String(u"List is the same by ListId: ") + (System::ObjectExt::Equals(lists->GetListByListId(1), list))) << std::endl;

◆ Is()

virtual bool Aspose::Words::Lists::ListCollection::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ Type()

static const System::TypeInfo& Aspose::Words::Lists::ListCollection::Type ( )
static