In modern programming, creating user-friendly and interactive user interfaces is an essential task. This is especially true when working with documents, forms, reports, and other data formats. In this article, we will discuss in detail how to implement a drop-down list form in C# and .NET using the SautinSoft Document .NET library.
A drop-down list is an interface element that displays a set of options from which the user can select one or more. It is widely used in forms, menus, settings, and documents to simplify data entry, increase convenience, and reduce errors. Usage examples:
Creating a drop-down list form allows you to automate the process of filling in and processing data, improve the quality of input data and save users time. For example, automatic generation of document templates with preset options, which is especially important in business reports, contracts, and licenses. The use of automated solutions in document management is a growing trend. Companies are actively implementing automated templates and forms, where drop-down list elements are a mandatory part.
Step-by-step guide:
This code example shows how to create a document containing FormDropDown element.
Complete code
using SautinSoft.Document;
using System.Linq;
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Get your free trial key here:
// https://sautinsoft.com/start-for-free/
FormDropDown();
}
/// <summary>
/// Creates a document containing FormDropDown element.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/advanced.php
/// </remarks>
static void FormDropDown()
{
string filePath = @"Advanced.pdf";
// Let's create document.
DocumentCore dc = new DocumentCore();
dc.Content.End.Insert(new Paragraph(dc, "The paragraph with FormDropDown element: ").Content);
Paragraph par = dc.GetChildElements(true, ElementType.Paragraph).FirstOrDefault() as Paragraph;
FormDropDownData field = new Field(dc, FieldType.FormDropDown).FormData as FormDropDownData;
field.Items.Add("First Item");
field.Items.Add("Second Item");
field.Items.Add("Third Item");
field.SelectedItemIndex = 2;
par.Inlines.Add(field.Field);
// Save our document.
dc.Save(filePath);
// Open the result for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
}
}
}Imports SautinSoft.Document
Imports System.Linq
Module Sample
Sub Main()
FormDropDown()
End Sub
''' Get your free trial key here:
''' https://sautinsoft.com/start-for-free/
''' <summary>
''' Creates a document containing FormDropDown element.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/advanced.php
''' </remarks>
Sub FormDropDown()
Dim filePath As String = "Advanced.pdf"
' Let's create document.
Dim dc As New DocumentCore()
dc.Content.End.Insert((New Paragraph(dc, "The paragraph with FormDropDown element: ")).Content)
Dim par As Paragraph = TryCast(dc.GetChildElements(True, ElementType.Paragraph).FirstOrDefault(), Paragraph)
Dim field As FormDropDownData = TryCast((New Field(dc, FieldType.FormDropDown)).FormData, FormDropDownData)
field.Items.Add("First Item")
field.Items.Add("Second Item")
field.Items.Add("Third Item")
field.SelectedItemIndex = 2
par.Inlines.Add(field.Field)
' Save our document.
dc.Save(filePath)
' Open the result for demonstration purposes.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
End Sub
End ModuleIf you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: