AGtk 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AGtk --version 0.1.1
                    
NuGet\Install-Package AGtk -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AGtk" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AGtk" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="AGtk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AGtk --version 0.1.1
                    
#r "nuget: AGtk, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=AGtk&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=AGtk&version=0.1.1
                    
Install as a Cake Tool

AGtk

AGtk is a library of helper classes for GTK 4 in C#. Well, actually at the moment there's only one helper class: AGtk.ColView. But perhaps I'll add more in the future.

AGtk.ColView

AGtk.ColView is a subclass of the Gtk.ColumnView class, which displays a multi-column list. Gtk.ColumnView has a complicated API, so AGtk.ColView exists to make it much easier to use. Here's a brief code sample to show how easy it is:

AGtk.ColView col_view = new(["year", "title", "director"]);

col_view.Add([1981, "Raiders of the Lost Ark", "Steven Spielberg"]);
col_view.Add([1994, "The Shawshank Redemption", "Frank Darabont"]);
col_view.Add([1995, "Clueless", "Amy Heckerling"]);
...

my_window.Child = col_view;

That will produce a column view that looks like this:

column view

Adding filtering

AGtk.ColView supports dynamic filtering. Typically you'll use this with a search box: as the user types in the box, rows will be filtered. Here's how to do this in code:

// specify the column to use for filtering
col_view.FilterColumn = 1;   // title

SearchEntry entry = new();
entry.OnSearchChanged += on_search_changed;

...

void on_search_changed(SearchEntry sender, EventArgs args) {
    col_view.FilterText = entry.GetText();
}

A larger example

My page Introduction to GTK 4 in C# contains a complete example of a program using AGtk.ColView.

Sorting

It would be nice if the user could click a column header to sort by that column. Unfortunately that's not yet possible due to limitations in the Gir.Core binding for GTK 4. I hope I'll be able to work with the Gir.Core developers to improve this situation before long.

Using the library

Perhaps I'll publish a nuget package at some point, but this is an early work in progress so I haven't done that yet. In the meantime, you can clone this repository to your machine, then use the dotnet add reference command to add a reference to agtk.csproj in your project:

$ dotnet add reference /path/to/agtk.csproj

API reference

All members listed below are public.

ColView

<dl> <dt><code>ColView(params string[] names)</code></dt> <dd>Create a ColView with the given column names.</dd> <dt><code>void Add(params object[] values)</code></dt> <dd>Append a row of values to the view.</dd> <dt><code>void Clear()</code></dt> <dd>Remove all rows from the view.</dd> <dt><code>int? FilterColumn {get; set; }</code></dt> <dd>The index of the column used for filtering.</dd> <dt><code>string FilterText {get; set; }</code></dt> <dd>The text to use for filtering. Only rows whose filter column contains this text will be shown. If the value is "", all rows will be displayed.</dd> <dt><code>RowList Rows {get;}</code></dt> <dd>A list of rows in this ColView.</dd> <dt><code>uint SelectedIndex {get;}</code></dt> <dd>The index of the row that is currently selected.</dd> <dt><code>event SelectionChanged? OnSelectionChanged</code></dt> <dd>An event that fires whenever the selection changes.</dd> </dl>

Row

A row in the column view.

<dl> <dt><code>object[] Values { get; }</code></dt> <dd>An array of values in the row.</dd> </dl>

RowList

A list of rows.

<dl> <dt><code>Row this[uint i] { get; }</code></dt> <dd>An indexer to retrieve a Row.</dd> </dl>

SelectedChanged

<dl> <dt><code>delegate void SelectionChanged(uint rowIndex)</code></dt> <dd>A delegate type for a selection change event. rowIndex will contain the currently selected row.</dd> </dl>

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 126 2/19/2025
0.4.1 115 2/19/2025
0.4.0 102 2/18/2025
0.3.3 118 2/18/2025
0.3.2 114 2/17/2025
0.3.1 101 2/16/2025
0.3.0 111 2/16/2025
0.2.0 108 2/16/2025
0.1.1 108 2/15/2025
0.1.0 100 2/15/2025