# Read-Only ListBox

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>ListBox for Blazor</td>
        </tr>
    </tbody>
</table>

## Description

I want to make the [ListBox](https://www.telerik.com/blazor-ui/documentation/components/listbox/overview) read-only. I am looking for a solution that doesn't allow users to modify the selected items or interact with the toolbar.

## Solution

To achieve a read-only effect in the TelerikListBox, follow these steps:

1. Use one-way binding for the `SelectedItems` parameter of the component.
2. Define a [`SelectedItemsChanged` event](https://www.telerik.com/blazor-ui/documentation/components/listbox/events#selecteditemschanged) handler, but avoid updating the `SelectedItems` parameter in the handler.
3. Hide the ListBox toolbar by setting the `Visible` property of the `ListBoxToolBar` to `false`.

Here is an example:

```RAZOR
<TelerikListBox Data="@ListBoxStrings"
                SelectedItems="@ListBoxSelectedStrings"
                SelectedItemsChanged="@((IEnumerable<string> list) => ListBoxSelectedStringsHandler(list))"
                Height="auto">
    <ListBoxToolBarSettings>
        <ListBoxToolBar Visible="false" />
    </ListBoxToolBarSettings>
</TelerikListBox>

@code {
    private List<string> ListBoxStrings { get; set; } = new List<string>();
    private IEnumerable<string> ListBoxSelectedStrings { get; set; } = new List<string>();

    private void ListBoxSelectedStringsHandler(IEnumerable<string> list)
    {
        // You can execute custom logic here, but do not update ListBoxSelectedStrings
        // to prevent the user from changing the selection.
    }

    protected override void OnInitialized()
    {
        for (int i = 1; i <= 7; i++)
        {
            ListBoxStrings.Add($"String {i}");
        }

        ListBoxSelectedStrings = new List<string> { "String 2", "String 5" };
    }
}
```

## See Also

* [TelerikListBox Overview](https://www.telerik.com/blazor-ui/documentation/components/listbox/overview)
* [TelerikListBox Events](https://www.telerik.com/blazor-ui/documentation/components/listbox/events)
* [TelerikListBox Toolbar](https://www.telerik.com/blazor-ui/documentation/components/listbox/toolbar)
