---
title: "Build a select dropdown in a C# desktop app"
url: https://recursiveai.org/oneapp/cookbook/build-desktop-select-dropdown/
description: "Bind a SelectBox and its choices to a C# SelectModel. Give the dropdown an accessible name and read the selected value without parsing its label."
version: "1.1.1"
---

Share one `SelectModel` between the dropdown and its choices. This example uses OneApp’s [desktop host](https://github.com/recursive-ai-oss/oneapp-csharp/blob/b93a90dc510817e92a4ebd1e340b83118461665c/README.md#L62-L68) on Linux, Windows, or macOS on Apple silicon.

```shell
dotnet add package RecursiveAI.OneApp.Kit
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```html
<!-- Delivery: SelectModel in DeliveryPage.cs. -->
<SelectBox Model="{Delivery}"
  TriggerId="shipping"
  AriaLabel="Delivery method">
  <SelectItem Model="{Delivery}"
    Value="standard" Text="Standard" />
  <SelectItem Model="{Delivery}"
    Value="express" Text="Express" />
</SelectBox>
```

[The example](https://recursiveai.org/oneapp/cookbook/build-desktop-select-dropdown/build-desktop-select-dropdown.zip) is the full program below: unzip it and `dotnet run`.

The dropdown starts on **Standard** and lets the user choose **Express**.

## Full program

OneApp hosts the window, OneApp.Kit supplies the controls, and OneUI compiles the `.html` component.

The zip contains the three files below and `Demo.csproj`. To make the project by hand, create a .NET 10 console app and install the packages above. The example’s project references are:

```xml
<PackageReference
  Include="RecursiveAI.OneApp"
  Version="1.1.1" />
<PackageReference
  Include="RecursiveAI.OneApp.Kit"
  Version="1.1.1" />
<PackageReference
  Include="RecursiveAI.OneUI"
  Version="1.1.0" />
```

OneUI compiles `DeliveryPage.html` into the other half of the partial class in `DeliveryPage.cs`, supplying the base component whose `OnMounted` method the example overrides. Save these files beside the project file.

`DeliveryPage.html`:

```html
<Theme>
  <main style="padding: 24px">
    <Label For="shipping">Delivery method</Label>
    <SelectBox Model="{Delivery}" Id="shipping-options"
               TriggerId="shipping" AriaLabel="Delivery method"
               Placeholder="Choose delivery" Width="180px">
      <SelectItem Model="{Delivery}"
                  Value="standard" Text="Standard" />
      <SelectItem Model="{Delivery}"
                  Value="express" Text="Express" />
    </SelectBox>
  </main>
</Theme>
```

`DeliveryPage.cs`:

```csharp
using OneApp.Kit;

public partial class DeliveryPage
{
    public SelectModel Delivery { get; } =
        new("standard");

    protected override void OnMounted() => Delivery.ValueChanged += Report;
    protected override void OnDisposed() => Delivery.ValueChanged -= Report;

    private static void Report(string? value) => Console.WriteLine($"Delivery: {value}");
}
```

`Program.cs` opens the native window. Checked on Linux (X11) with OneApp 1.1.1:

```csharp
using OneApp;

using var host = AppHost.Create(new AppOptions(new DeliveryPage())
{
    Title = "Delivery",
    Width = 420,
    Height = 300,
});
host.Run();
```

Press Tab to focus the dropdown, Down Arrow to open it, Down Arrow again to highlight **Express**, and Enter to commit. The trigger now says **Express**, and the terminal prints:

```text
Delivery: express
```

If a choice doesn’t update the trigger, check that the `SelectBox` and every `SelectItem` use the same `SelectModel` instance.

![Build a select dropdown in a C# desktop app: example window](https://recursiveai.org/oneapp/images/build-desktop-select-dropdown/window.png)

## Variations

To open the list under the trigger instead of aligning the selected item with it, add `Position` to the opening tag in `DeliveryPage.html`:

```html
<SelectBox Model="{Delivery}" Id="shipping-options"
  TriggerId="shipping" AriaLabel="Delivery method"
  Placeholder="Choose delivery" Width="180px"
  Position="{OneApp.Kit.SelectPosition.Below}">
```

## Related recipes

- [Build a desktop app with HTML and CSS in C#](https://recursiveai.org/oneapp/cookbook/build-desktop-app-with-html-css/)
- [Customize desktop dark mode and colors](https://recursiveai.org/oneapp/cookbook/theme-desktop-ui-kit/)

## The short answer

Bind `SelectBox` and each `SelectItem` to one C# `SelectModel`. Use `Text` for the label and `Value` for the stored identifier. Read `Delivery.Value` to get the chosen identifier or handle `ValueChanged` to react when it changes.

## How do I set the choices and default value in a C# dropdown?

Start the model with a value that matches one of the items. The sample starts with `standard`, so the control displays **Standard**. For a required choice with no default, start with a model that has no value, set `Placeholder`, and check for a choice before proceeding. Give options unique, stable values so changing a label doesn’t change the data your app stores. Use `SelectBox` for a choice the app keeps; use a command menu for actions such as Print or Export.

## How do I use a select dropdown with the keyboard?

The trigger is a select-only combobox: it has a list of choices but no editable text field. Use `AriaLabel` for the control’s name, `TriggerId` to connect the visible `Label`, and `Id` for the listbox. Focus stays on the trigger while `aria-activedescendant` identifies the highlighted option. Arrow keys move the highlight; Home and End go to the first or last choice. Enter or Space commits it, Tab commits and moves on, and Escape closes without committing. Typing a letter can jump to a matching label; on the closed control it chooses the match.
