Skip to main content
All docs
V23.2

DxListBox<TData, TValue>.Columns Property

Allows you to add columns to the List Box.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public RenderFragment Columns { get; set; }

Property Value

Type Description
RenderFragment

A (render fragments) that allow you to declare List Box columns.

Remarks

The ListBox control can display data across multiple columns. Follow the steps below to create columns:

  1. Add a <Columns> tag to the component’s markup to declare the column collection.
  2. Populate the Columns collection with DxListEditorColumn objects. These objects include the following properties:

    • FieldName - Specifies the data source field that populates column items.
    • Caption - Specifies the column header.
    • Visible - Specifies column visibility.
    • VisibleIndex - Specifies column position.
    • Width - Specifies column width.
@using StaffData

<DxListBox Data="@Staff.DataSource"
           @bind-Values="@Values">
    <Columns>
        <DxListEditorColumn FieldName="Id" Width="50px" />
        <DxListEditorColumn FieldName="FirstName" Caption="Name"/>
        <DxListEditorColumn FieldName="LastName" Caption="Surname"/>
    </Columns>
</DxListBox>

@code {
    IEnumerable<Person> Values { get; set; } = Staff.DataSource.Take(1);
}

List Box - Multiple Columns

Run Demo: List Box – Multiple Columns

Note that if you implement custom logic to arrange columns based on specified conditions, the List Box places conditional columns last. The following code demonstrates conditional render for columns:

<DxListBox TData="@(WebApiLookup)"
            TValue="string"
            Data="@_data"
            CssClass="cw-400 chi-220">
    <Columns>
            @if(ShowColumn) {
                <DxListEditorColumn FieldName="Text"></DxListEditorColumn>
            }
            <DxListEditorColumn FieldName="Value"></DxListEditorColumn>
    </Columns>
</DxListBox>

<DxButton Text="ShowColumn" Click="@ShowHideColumn"></DxButton>

@code {
    IEnumerable<WebApiLookup> _data;

    bool ShowColumn {  get; set;  }

    void ShowHideColumn() {
        ShowColumn = !ShowColumn;
    }

    protected override Task OnInitializedAsync() {
        _data = Enumerable.Range(0, 100).Select(id => new WebApiLookup { Text = $"Text-{id}", Value = $"Value_{id}" });
        return base.OnInitializedAsync();
    }

    public class WebApiLookup {
        public string Text { get; set; }
        public string Value { get; set; }
    }
}

Conditional Render

See Also