menu

Blazor

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class ListBoxField - Blazor API Reference | Syncfusion

    Show / Hide Table of Contents

    Class ListBoxField

    Represents a list box field in the SfPdfViewer2 component.

    Inheritance
    System.Object
    FormFieldInfo
    ListBoxField
    Inherited Members
    FormFieldInfo.BackgroundColor
    FormFieldInfo.BorderColor
    FormFieldInfo.Bounds
    FormFieldInfo.Color
    FormFieldInfo.CustomData
    FormFieldInfo.FontFamily
    FormFieldInfo.FontSize
    FormFieldInfo.FontStyle
    FormFieldInfo.Id
    FormFieldInfo.IsReadOnly
    FormFieldInfo.IsRequired
    FormFieldInfo.Name
    FormFieldInfo.PageNumber
    FormFieldInfo.TextAlignment
    FormFieldInfo.Thickness
    FormFieldInfo.TooltipText
    FormFieldInfo.Type
    FormFieldInfo.Visibility
    Namespace: Syncfusion.Blazor.SfPdfViewer
    Assembly: Syncfusion.Blazor.SfPdfViewer.dll
    Syntax
    public class ListBoxField : FormFieldInfo
    Remarks

    Initializes a new instance of the ListBoxField class with the default field type set to "ListBox."
    This field allows users to select one or multiple options from a predefined list in interactive PDF forms.

    Examples
    ListBoxField listBoxField = new ListBoxField();
    listBoxField.Name = "Options";
    
    // Adds options to the list box
    listBoxField.Items = new List<ListItem> {
        new ListItem { Name = "Option 1", Value = "Value 1" },
        new ListItem { Name = "Option 2", Value = "Value 2" },
        new ListItem { Name = "Option 3", Value = "Value 3" }
    };
    
    listBoxField.SelectedIndexes = new List<int> { 0, 2 }; // Selects "Option 1" and "Option 3"
    
    await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { listBoxField });

    Constructors

    ListBoxField()

    Initializes a new instance of the ListBoxField class in the SfPdfViewer2 component.

    Declaration
    public ListBoxField()
    Remarks

    This constructor creates a list box field with the default field type set to "ListBox."
    List box fields allow users to select one or multiple options from a predefined list in interactive PDF forms.

    Examples
    ListBoxField listBoxField = new ListBoxField();
    listBoxField.Name = "Options";
    
    // Adds options to the list box
    listBoxField.Items = new List<ListItem> {
        new ListItem { Name = "Option 1", Value = "Value 1" },
        new ListItem { Name = "Option 2", Value = "Value 2" },
        new ListItem { Name = "Option 3", Value = "Value 3" }
    };
    
    listBoxField.SelectedIndexes = new List<int> { 0, 2 }; // Selects "Option 1" and "Option 3"
    
    await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { listBoxField });

    Properties

    Items

    Gets or sets the list of selectable options in the ListBoxField of the SfPdfViewer2 component.

    Declaration
    public List<ListItem> Items { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.List<ListItem>

    A list of ListItem containing the available options for the list box field.

    Remarks

    The Items property holds a collection of ListItem objects,
    each representing an option available in the list box field.
    Developers can populate this list with predefined choices for users to select from.

    Examples

    The following example demonstrates how to add options to a list box field:

    ListBoxField listBoxField = new ListBoxField();
    listBoxField.Name = "Options";
    
    // Adds options to the list box
    listBoxField.Items = new List<ListItem> {
        new ListItem { Name = "Option 1", Value = "Value 1" },
        new ListItem { Name = "Option 2", Value = "Value 2" },
        new ListItem { Name = "Option 3", Value = "Value 3" }
    };
    
    listBoxField.SelectedIndexes = new List<int> { 0, 2 }; // Selects "Option 1" and "Option 3"
    
    await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { listBoxField });

    SelectedIndexes

    Gets or sets the zero-based indexes of the selected items in the ListBoxField of the SfPdfViewer2 component.

    Declaration
    public int[] SelectedIndexes { get; set; }
    Property Value
    Type Description
    System.Int32[]

    An array of System.Int32 values representing the zero-based indexes of the selected items.

    Remarks

    This property holds an array of integers representing the zero-based indexes of the selected items in the list box. If the list box allows multiple selections, this property contains the indexes of all selected items. An empty array indicates that no items are selected.

    Examples

    The following example demonstrates how to set the selected item indexes in the ListBoxField:

    ListBoxField listBoxField = new ListBoxField();
    listBoxField.Name = "Options";
    
    // Adds options to the list box
    listBoxField.Items = new List<ListItem> {
        new ListItem { Name = "Option 1", Value = "Value 1" },
        new ListItem { Name = "Option 2", Value = "Value 2" },
        new ListItem { Name = "Option 3", Value = "Value 3" }
    };
    
    listBoxField.SelectedIndexes = new List<int> { 0, 2 }; // Selects "Option 1" and "Option 3"
    
    await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { listBoxField });
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved