search/mag_sel search/close
Aspose::Words::Markup::SdtListItemCollection Class Reference

Provides access to SdtListItem elements of a structured document tag.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

#include <Aspose.Words.Cpp/Markup/SdtListItemCollection.h>

+ Inheritance diagram for Aspose::Words::Markup::SdtListItemCollection:

Public Types

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

Public Member Functions

void Add (SharedPtr< SdtListItem > item)
 Adds an item to this collection. More...
 
const_iterator begin () const noexcept
 
iterator begin () noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
void Clear ()
 Clears all items from this collection. More...
 
const_iterator end () const noexcept
 
iterator end () noexcept
 
int32_t get_Count ()
 Gets number of items in the collection. More...
 
SharedPtr< SdtListItemget_SelectedValue ()
 Specifies currently selected value in this list. Null value allowed, meaning that no currently selected entry is associated with this list item collection. More...
 
SharedPtr< IEnumerator< SharedPtr< SdtListItem > > > GetEnumerator () override
 Returns an enumerator object that can be used to iterate over all items in the collection. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< SdtListItemidx_get (int32_t index)
 Returns a SdtListItem object given its zero-based index in the collection. More...
 
virtual bool Is (const TypeInfo &target) const override
 
void RemoveAt (int32_t index)
 Removes a list item at the specified index. More...
 
void set_SelectedValue (SharedPtr< SdtListItem > value)
 Setter for get_SelectedValue. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Typedef Documentation

◆ const_iterator

◆ iterator

◆ iterator_holder_type

Member Function Documentation

◆ Add()

void Aspose::Words::Markup::SdtListItemCollection::Add ( System::SharedPtr< Aspose::Words::Markup::SdtListItem item)

Adds an item to this collection.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ begin() [1/2]

const_iterator Aspose::Words::Markup::SdtListItemCollection::begin ( ) const
noexcept

◆ begin() [2/2]

iterator Aspose::Words::Markup::SdtListItemCollection::begin ( )
noexcept

◆ cbegin()

const_iterator Aspose::Words::Markup::SdtListItemCollection::cbegin ( ) const
noexcept

◆ cend()

const_iterator Aspose::Words::Markup::SdtListItemCollection::cend ( ) const
noexcept

◆ Clear()

void Aspose::Words::Markup::SdtListItemCollection::Clear ( )

Clears all items from this collection.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ end() [1/2]

const_iterator Aspose::Words::Markup::SdtListItemCollection::end ( ) const
noexcept

◆ end() [2/2]

iterator Aspose::Words::Markup::SdtListItemCollection::end ( )
noexcept

◆ get_Count()

int32_t Aspose::Words::Markup::SdtListItemCollection::get_Count ( )

Gets number of items in the collection.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ get_SelectedValue()

System::SharedPtr<Aspose::Words::Markup::SdtListItem> Aspose::Words::Markup::SdtListItemCollection::get_SelectedValue ( )

Specifies currently selected value in this list. Null value allowed, meaning that no currently selected entry is associated with this list item collection.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Markup::SdtListItem> > > Aspose::Words::Markup::SdtListItemCollection::GetEnumerator ( )
override

Returns an enumerator object that can be used to iterate over all items in the collection.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Markup::SdtListItemCollection::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ idx_get()

System::SharedPtr<Aspose::Words::Markup::SdtListItem> Aspose::Words::Markup::SdtListItemCollection::idx_get ( int32_t  index)

Returns a SdtListItem object given its zero-based index in the collection.

Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ Is()

virtual bool Aspose::Words::Markup::SdtListItemCollection::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ RemoveAt()

void Aspose::Words::Markup::SdtListItemCollection::RemoveAt ( int32_t  index)

Removes a list item at the specified index.

Parameters
indexThe zero-based index of the item to remove.
Examples

Shows how to work with drop down-list structured document tags.

auto doc = MakeObject<Document>();
auto tag = MakeObject<StructuredDocumentTag>(doc, SdtType::DropDownList, MarkupLevel::Block);
doc->get_FirstSection()->get_Body()->AppendChild(tag);
// A drop-down list structured document tag is a form that allows the user to
// select an option from a list by left-clicking and opening the form in Microsoft Word.
// The "ListItems" property contains all list items, and each list item is an "SdtListItem".
SharedPtr<SdtListItemCollection> listItems = tag->get_ListItems();
listItems->Add(MakeObject<SdtListItem>(u"Value 1"));
ASSERT_EQ(listItems->idx_get(0)->get_DisplayText(), listItems->idx_get(0)->get_Value());
// Add 3 more list items. Initialize these items using a different constructor to the first item
// to display strings that are different from their values.
listItems->Add(MakeObject<SdtListItem>(u"Item 2", u"Value 2"));
listItems->Add(MakeObject<SdtListItem>(u"Item 3", u"Value 3"));
listItems->Add(MakeObject<SdtListItem>(u"Item 4", u"Value 4"));
ASSERT_EQ(4, listItems->get_Count());
// The drop-down list is displaying the first item. Assign a different list item to the "SelectedValue" to display it.
listItems->set_SelectedValue(listItems->idx_get(3));
ASSERT_EQ(u"Value 4", listItems->get_SelectedValue()->get_Value());
// Enumerate over the collection and print each element.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<SdtListItem>>> enumerator = listItems->GetEnumerator();
while (enumerator->MoveNext())
{
if (enumerator->get_Current() != nullptr)
{
std::cout << "List item: " << enumerator->get_Current()->get_DisplayText() << ", value: " << enumerator->get_Current()->get_Value()
<< std::endl;
}
}
}
// Remove the last list item.
listItems->RemoveAt(3);
ASSERT_EQ(3, listItems->get_Count());
// Since our drop-down control is set to display the removed item by default, give it an item to display which exists.
listItems->set_SelectedValue(listItems->idx_get(1));
doc->Save(ArtifactsDir + u"StructuredDocumentTag.ListItemCollection.docx");
// Use the "Clear" method to empty the entire drop-down item collection at once.
listItems->Clear();
ASSERT_EQ(0, listItems->get_Count());

◆ set_SelectedValue()

void Aspose::Words::Markup::SdtListItemCollection::set_SelectedValue ( System::SharedPtr< Aspose::Words::Markup::SdtListItem value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Markup::SdtListItemCollection::Type ( )
static