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

This element specifies a single list item within a parent ComboBox or DropDownList 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/SdtListItem.h>

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

Public Member Functions

 SdtListItem (String displayText, String value)
 Initializes a new instance of this class. More...
 
 SdtListItem (String value)
 Initializes a new instance of this class. More...
 
String get_DisplayText () const
 Gets the text to display in the run content in place of the Value attribute contents for this list item. More...
 
String get_Value () const
 Gets the value of this list item. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ SdtListItem() [1/2]

Aspose::Words::Markup::SdtListItem::SdtListItem ( System::String  displayText,
System::String  value 
)

Initializes a new instance of this class.

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());

◆ SdtListItem() [2/2]

Aspose::Words::Markup::SdtListItem::SdtListItem ( System::String  value)

Initializes a new instance of this class.

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());

Member Function Documentation

◆ get_DisplayText()

System::String Aspose::Words::Markup::SdtListItem::get_DisplayText ( ) const

Gets the text to display in the run content in place of the Value attribute contents for this list item.

Cannot be null and cannot be an empty string.

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_Value()

System::String Aspose::Words::Markup::SdtListItem::get_Value ( ) const

Gets the value of this list item.

Cannot be null and cannot be an empty string.

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::SdtListItem::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ Type()

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