s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationUiVirtualgrid
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/UI
UI

VirtualGrid

VirtualGrid is a Panel that allows you to create a grid of items virtually. What this means is that if you have 1 million items, it won't render them and try to lay them all out at the same time. It'll just pick the few that are visible and create them. When you scroll down, it'll delete the ones it can no longer see and create the new visible ones.

An example usage of VirtualGrid

You can use it in Razor like this

<VirtualGrid Items=@Items ItemSize=@(120)>
    <Item Context="item">
        @if (item is Package entry)
        {
            <SpawnButton Icon="@entry.Thumb" Action="@(() => Spawn(entry))"></SpawnButton>
        }
    </Item>
</VirtualGrid>
  
@code
{
    public Package[] Items{ get; set; }
}

Here you can see that it sets the Items property (which takes any IEnumerable<T>) and the ItemSize.

Item defines the cell contents. The cell has the class "cell" and will contain whatever you put in between the <Item> elements.

ItemSize is a Vector2. The cell size will be scaled up so it fits into the parent container flush. It'll keep the aspect ratio of the ItemSize.

Gotchas

You need to make sure that VirtualGrid has a size in your styles. I usually make it width and height 100%.

All items obviously need to be the same size.

You can add spacing between elements using the gap styles on the VirtualGrid element.

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2025-08-30. Read it rendered on the official docs.

More in UI

HudPainter
Localization
Razor Components
Razor Panels
Style Properties
Styling Panels
UI
UI Interactions
← All documentation

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.