ElementCollectionRemoveAt Method |
Removes the element at the specified index.
Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.12.16
Syntax public void RemoveAt(
int index
)
Public Sub RemoveAt (
index As Integer
)
Parameters
- index Int32
- The zero-based index of the element to remove.
Exceptions Exception | Condition |
---|
ArgumentOutOfRangeException | index is not a valid index in the IList. |
NotSupportedException | The IList is read-only.-or- The IList has a fixed size. |
Example See Developer Guide: ElementCollection: Adds 20 paragraphs into document and delete 10 of them
ElementCollection: Adds 20 paragraphs into document and delete 10 of them in C#
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main(string[] args)
{
AddAndDeleteParagraphs();
}
static void AddAndDeleteParagraphs()
{
DocumentCore dc = new DocumentCore();
Section section = new Section(dc);
dc.Sections.Add(section);
for (int i = 0; i < 20; i++)
{
Paragraph par = new Paragraph(dc,"Text "+ i.ToString());
section.Blocks.Add(par);
}
dc.Save("ResultFull.docx");
for (int i = 0; i < section.Blocks.Count; )
{
section.Blocks.RemoveAt(i);
i++;
}
dc.Save("ResultShort.docx");
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("ResultFull.docx") { UseShellExecute = true });
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("ResultShort.docx") { UseShellExecute = true });
}
}
}
ElementCollection: Adds 20 paragraphs into document and delete 10 of them in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
Sub Main()
AddAndDeleteParagraphs()
End Sub
Sub AddAndDeleteParagraphs()
Dim dc As New DocumentCore()
Dim section As New Section(dc)
dc.Sections.Add(section)
For i As Integer = 0 To 19
Dim par As New Paragraph(dc, "Text " & i.ToString())
section.Blocks.Add(par)
Next i
dc.Save("ResultFull.docx")
Dim j As Integer = 0
Do While j < section.Blocks.Count
section.Blocks.RemoveAt(j)
j += 1
Loop
dc.Save("ResultShort.docx")
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("ResultFull.docx") With {.UseShellExecute = True})
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("ResultShort.docx") With {.UseShellExecute = True})
End Sub
End Module
See Also