### Install SimpleBlazorMultiselect Package Source: https://github.com/borisgerretzen/simpleblazormultiselect/blob/master/README.md Install the SimpleBlazorMultiselect NuGet package using the .NET CLI. ```bash dotnet add package SimpleBlazorMultiselect ``` -------------------------------- ### Blazor Component Setup Source: https://github.com/borisgerretzen/simpleblazormultiselect/blob/master/README.md This C# code block defines the data source for the multiselect component. It includes a list of strings for options and a HashSet to store selected items. ```csharp @code { private readonly List _items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" ]; private HashSet _selectedItems = new(); } ``` -------------------------------- ### Configure Global Standalone Mode Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Set `SimpleMultiselectGlobals.Standalone = true` once at application startup to enable standalone mode. This includes bundled CSS variables, making Bootstrap unnecessary. ```csharp // Program.cs — Blazor Server using SimpleBlazorMultiselect; var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents().AddInteractiveServerComponents(); // Run without Bootstrap across the entire app SimpleMultiselectGlobals.Standalone = true; var app = builder.Build(); // ... await app.RunAsync(); ``` ```csharp // Program.cs — Blazor WebAssembly using SimpleBlazorMultiselect; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); SimpleMultiselectGlobals.Standalone = true; await builder.Build().RunAsync(); ``` -------------------------------- ### Configure Standalone Mode for No Bootstrap Projects Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt For projects not using Bootstrap, set the global standalone flag in `Program.cs` to enable standalone styling for the multiselect component. ```csharp // Program.cs (Blazor Server or WASM) using SimpleBlazorMultiselect; // ... SimpleMultiselectGlobals.Standalone = true; await app.RunAsync(); ``` -------------------------------- ### Basic Multiselect with String Options Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Demonstrates the basic usage of the `SimpleMultiselect` component, binding to a list of strings and displaying selected items. Requires `Options` and `@bind-SelectedOptions`. ```razor @* Basic multiselect bound to a list of strings *@
    @foreach (var item in _selectedItems) {
  • @item
  • }
@code { private readonly List _items = ["Apple", "Banana", "Cherry", "Date", "Elderberry"]; private HashSet _selectedItems = new(); } ``` -------------------------------- ### Register SimpleBlazorMultiselect Namespace Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Import the component's namespace into your Blazor project's `_Imports.razor` file to make the component available. ```razor @* _Imports.razor *@@using SimpleBlazorMultiselect ``` -------------------------------- ### Virtualization for Large Datasets with Virtualize Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Improve performance for large lists by setting `Virtualize` to `true`. This uses Blazor's `` component to render only visible items, recommended when paired with `CanFilter`. ```razor @code { // 100 000 items rendered efficiently private readonly List _bigList = Enumerable.Range(1, 100_000).Select(i => $"Item {i}").ToList(); private HashSet _selected = new(); } ``` -------------------------------- ### Component Properties Source: https://github.com/borisgerretzen/simpleblazormultiselect/wiki/Properties This section lists and describes the properties available for configuring the Simple Blazor Multiselect component. ```APIDOC ## Component Properties ### Description This table outlines the properties that can be used to customize the behavior and appearance of the Simple Blazor Multiselect component. ### Properties - **SelectedOptions** (List) - Required - The options selected by the user. Default: `new()` - **SelectedOptionsChanged** (EventCallback>) - Required - Event callback that is invoked when the selected options change. - **Options** (List) - Required - Represents the available options in the multiselect dropdown. Default: `new()` - **StringSelector** (Func) - Required - Function to convert an item to a string for display in the dropdown. Default: `item => item?.ToString() ?? string.Empty` - **DefaultText** (string) - Optional - The default text to display when no options are selected. Default: `"Select Options"` - **SelectedOptionsRenderer** (RenderFragment>?) - Optional - Optional custom renderer for the selected options. If not set, items will be rendered using StringSelector and concatenated with a comma. - **CanFilter** (bool) - Optional - Whether or not the dropdown should be filterable. Default: `false` - **FilterPredicate** (Func?) - Optional - A function that determines whether a given item matches the filter string. Default implementation checks if the item's string representation contains the filter string, case-insensitive. - **Virtualize** (bool) - Optional - Whether or not the virtualize component should be used to render the options. Default: `false` - **IsMultiSelect** (bool) - Optional - Whether or not the multiselect should allow multiple selected values. Default: `true` - **Class** (string?) - Optional - Additional CSS classes to apply to the dropdown. - **Style** (string?) - Optional - Additional CSS style to apply to the dropdown. ``` -------------------------------- ### Multiselect with String and Enum Options Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Shows how to use the `SimpleMultiselect` component with both string lists and enum types. For enums, `Enum.GetValues` and a `StringSelector` are used. ```razor @* String list *@ @* Enum list *@ @code { private readonly List _fruits = ["Apple", "Banana", "Cherry"]; private HashSet _selected = new(); private HashSet _selectedStatuses = new(); private enum Status { Active, Inactive, Pending } } ``` -------------------------------- ### Manual Event Handling with SelectedOptionsChanged Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Demonstrates manual event wiring for `SelectedOptionsChanged`, which is useful for executing side effects or custom logic when the selection changes. The `OnSelectionChanged` method handles the update. ```razor @* Manual event wiring — useful when side effects are needed *@

Count: @_selected.Count

@code { private readonly List _capitals = ["Berlin", "Paris", "Rome", "Madrid"]; private HashSet _selected = new(); private void OnSelectionChanged(HashSet newSelection) { _selected = newSelection; Console.WriteLine($"Selection changed: {string.Join(", ", newSelection)}"); } } ``` -------------------------------- ### Enabling Filtering with CanFilter and FilterPredicate Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Enable the search input in the dropdown by setting `CanFilter` to `true`. Customize the filtering logic by providing a `FilterPredicate` function for case-insensitive substring matching or custom logic. ```razor @* Default case-insensitive contains filter *@ @* Custom predicate: starts-with match only *@ @code { private readonly List _cities = ["Amsterdam", "Athens", "Berlin", "Brussels", "Budapest"]; private HashSet _selected = new(); private HashSet _selected2 = new(); } ``` -------------------------------- ### Basic Blazor Multiselect Usage Source: https://github.com/borisgerretzen/simpleblazormultiselect/blob/master/README.md Renders a basic multiselect dropdown using the SimpleMultiselect component. It binds the available options to the '_items' list and selected options to the '_selectedItems' HashSet. ```html ``` -------------------------------- ### Control Item Selection Comparison with MatchByReference Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Use `MatchByReference` to determine if a displayed item is already selected. Set to `true` for reference equality (instances must be identical), or `false` (default) for string equality based on `StringSelector` output. ```razor @* String equality (default) — works even when item instances differ *@@ @* Reference equality — instances must be identical *@ @code { private record MyItem(string Id, string Label); private readonly List _options = [ new("1", "Apple"), new("2", "Banana"), new("3", "Cherry") ]; // Pre-populate with the same instance from _options for MatchByReference to work correctly private HashSet _selected = new(); private HashSet _selected2 = new(); } ``` -------------------------------- ### Blazor Multiselect with Reference Equality Source: https://github.com/borisgerretzen/simpleblazormultiselect/blob/master/README.md Configures the SimpleMultiselect component to use reference equality for comparing selected items. Set `MatchByReference` to `true` to use the default equality comparison instead of string representation. ```html ``` -------------------------------- ### Blazor Multiselect with Custom Item Template Source: https://github.com/borisgerretzen/simpleblazormultiselect/blob/master/README.md Configures the SimpleMultiselect component to use a custom template for rendering selected items. Each selected item is displayed as a Bootstrap badge. ```html @foreach (var item in options) { @item } ``` -------------------------------- ### Custom String Display with StringSelector Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Use the `StringSelector` parameter to define how complex objects are converted to strings for display and selection. This is required when `TItem` is not a primitive type. ```razor
    @foreach (var p in _selectedPeople) {
  • @p.Name — @p.Age years old
  • }
@code { private record Person(string Name, int Age); private readonly List _people = [ new("Alice", 30), new("Bob", 25), new("Charlie", 35) ]; private HashSet _selectedPeople = new(); } ``` -------------------------------- ### Two-Way Binding with @bind-SelectedOptions Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Illustrates the use of Blazor's `@bind-SelectedOptions` shorthand for two-way data binding between the component's selection and a local `HashSet`. ```razor @* Two-way binding shorthand *@

Count: @_selected.Count

@code { private readonly List _capitals = ["Berlin", "Paris", "Rome", "Madrid"]; private HashSet _selected = new(); } ``` -------------------------------- ### Blazor Multiselect with Filtering Enabled Source: https://github.com/borisgerretzen/simpleblazormultiselect/blob/master/README.md Enables the filtering capability for the SimpleMultiselect component, allowing users to search through the options. Set `CanFilter` to `true`. ```html ``` -------------------------------- ### Use Cascading Parameter for Standalone Mode Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Alternatively, wrap individual component instances in a `CascadingValue` with `Standalone` set to `true` to enable standalone mode for specific components. ```razor ``` -------------------------------- ### Custom Selected Options Rendering with SelectedOptionsRenderer Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Utilize the `SelectedOptionsRenderer` parameter to completely customize how selected items are displayed within the dropdown button. This allows for custom elements like badges or pills. ```razor @if (!options.Any()) { Select capitals... } else { @foreach (var city in options) { @city } } @code { private readonly List _capitals = ["Berlin", "Paris", "Rome", "Madrid", "Lisbon"]; private HashSet _selected = new(); } ``` -------------------------------- ### Custom Default Text with DefaultText Parameter Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Set the `DefaultText` parameter to customize the string displayed in the dropdown button when no items are selected. The default value is 'Select Options'. ```razor @code { private readonly List _items = ["Option A", "Option B", "Option C"]; private HashSet _selected = new(); } ``` -------------------------------- ### Single Select Mode with IsMultiSelect Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Configure the component for single selection by setting `IsMultiSelect` to `false`. In this mode, selecting a new item closes the dropdown and clears previous selections. ```razor

Selected: @_selected.FirstOrDefault()

@code { private readonly List _countries = ["Germany", "France", "Italy", "Spain"]; private HashSet _selected = new(); } ``` -------------------------------- ### Apply Custom CSS Class and Inline Styles Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Pass additional CSS class names or inline styles to the outermost `
` wrapper of the component for custom theming or layout overrides. ```razor @code { private readonly List _items = ["Red", "Green", "Blue"]; private HashSet _selected = new(); } ``` -------------------------------- ### Set Dropdown ID for Accessibility Source: https://context7.com/borisgerretzen/simpleblazormultiselect/llms.txt Set the `id` attribute on the internal ` @code { private readonly List _items = ["Alpha", "Beta", "Gamma"]; private HashSet _selected = new(); private bool _isDisabled = false; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.