---
title: "Show data in a read-only table in C#"
url: https://recursiveai.org/oneapp/cookbook/render-read-only-table-in-desktop-app/
description: "Display a C# array as a read-only invoice table with column headers, a caption, and right-aligned amounts. No grid or database setup required."
version: "1.1.1"
---

This example shows an array of invoice records as a table. `TableBody` renders one row per record. 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
<!-- Invoices: array in InvoicesPage.cs. -->
<Table>
  <TableCaption>
    Recent invoices (USD)
  </TableCaption>
  <TableBody>
    <template each="{Invoices}"
              item="inv" key="{inv.Id}">
      <TableRow>
        <TableCell>{inv.Id}</TableCell>
        <TableCell>{inv.Status}</TableCell>
        <TableCell>{inv.Amount}</TableCell>
      </TableRow>
    </template>
  </TableBody>
</Table>
```

[The example](https://recursiveai.org/oneapp/cookbook/render-read-only-table-in-desktop-app/render-read-only-table-in-desktop-app.zip) is the full program below: unzip it and `dotnet run`.

The template makes one row per invoice; the full example adds column headings.

## 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 `InvoicesPage.html` into the other half of the partial class in `InvoicesPage.cs`. Save these files beside the project file.

`InvoicesPage.html`:

```html
<Theme>
  <main style="padding: 24px">
    <Table>
      <TableCaption>Recent invoices (USD)</TableCaption>
      <TableHeader>
        <TableRow>
          <TableHead>Invoice</TableHead>
          <TableHead>Status</TableHead>
          <TableHead
            Align="{OneApp.Kit.CellAlign.End}">
            Amount
          </TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        <template each="{Invoices}" item="inv" key="{inv.Id}">
          <TableRow>
            <TableCell>{inv.Id}</TableCell>
            <TableCell>{inv.Status}</TableCell>
            <TableCell Align="{OneApp.Kit.CellAlign.End}">{inv.Amount}</TableCell>
          </TableRow>
        </template>
      </TableBody>
    </Table>
  </main>
</Theme>
```

`InvoicesPage.cs`:

```csharp
public partial class InvoicesPage
{
    public record Invoice(string Id, string Status, string Amount);

    public Invoice[] Invoices { get; } =
    [
        new("INV-101", "Paid", "$120.00"),
        new("INV-102", "Open", "$45.50"),
    ];
}
```

`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 InvoicesPage())
{
    Title = "Invoices",
    Width = 420,
    Height = 255,
});
host.Run();
```

The window shows this table, with the caption **Recent invoices (USD)** below it:

| Invoice | Status | Amount |
| --- | --- | --- |
| INV-101 | Paid | $120.00 |
| INV-102 | Open | $45.50 |

If the headings appear but the rows don’t, check that `Invoices` contains records and that the loop is inside `TableBody`.

![Show data in a read-only table in C#: example window](https://recursiveai.org/oneapp/images/render-read-only-table-in-desktop-app/window.png)

## Variations

To emphasize invoice IDs without making them editable, replace the ID cell in `InvoicesPage.html`:

```html
<TableCell Medium="true">{inv.Id}</TableCell>
```

## 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

Use `TableHeader` and `TableHead` for the headings, then loop over the C# records in `TableBody`, rendering a `TableRow` with `TableCell` elements for each record. The cells display text; there is no edit mode to turn off.

## How do I display C# data in a read-only desktop table?

The sample uses an in-memory array, but the table only needs the collection you give it. Each invoice supplies a stable, unique `Id` as the template key, so the row’s identity doesn’t depend on where it appears in the list. Keep the header and the cell order the same, and put the unit in the caption instead of making the reader guess which currency the amounts use. `CellAlign.End` lines up the amounts at their trailing edge; use it on the heading too.

## Does a read-only table sort or page the data?

The kit renders table elements with their row and column semantics. It doesn’t sort, page, resize columns, or virtualize rows. Use it for a modest set of records such as a recent-invoices summary. If you need paging, pass only the current page of records to the template; if you need sorting, order the records before handing them to the table. Sort numeric invoice amounts as numbers, before formatting them for display. On a narrow window the table’s container scrolls horizontally; the cells don’t wrap.
