diff --git a/TreeDataGrid/FlatTreeDataGridSample/FlatTreeDataGridSample.csproj b/TreeDataGrid/FlatTreeDataGridSample/FlatTreeDataGridSample.csproj index bfd200b..dae1ebe 100644 --- a/TreeDataGrid/FlatTreeDataGridSample/FlatTreeDataGridSample.csproj +++ b/TreeDataGrid/FlatTreeDataGridSample/FlatTreeDataGridSample.csproj @@ -14,7 +14,7 @@ - + diff --git a/TreeDataGrid/FlatTreeDataGridSample/ViewModels/MainWindowViewModel.cs b/TreeDataGrid/FlatTreeDataGridSample/ViewModels/MainWindowViewModel.cs index 536051b..d427b3b 100644 --- a/TreeDataGrid/FlatTreeDataGridSample/ViewModels/MainWindowViewModel.cs +++ b/TreeDataGrid/FlatTreeDataGridSample/ViewModels/MainWindowViewModel.cs @@ -2,6 +2,7 @@ using System.Linq; using Avalonia.Controls; using Avalonia.Controls.Models.TreeDataGrid; +using Avalonia.Controls.Selection; using FlatTreeDataGridSample.Models; namespace FlatTreeDataGridSample.ViewModels; @@ -26,6 +27,11 @@ public MainWindowViewModel() { Columns = { + // Define a row header column for row numbering. This can be made to be always + // visible when scrolling horizontally by setting FrozenColumnCount = 1 on the + // TreeDataGrid. + new RowHeaderColumn(), + // Define a read/write text column for the country name with text search enabled. new TextColumn( "Country", @@ -52,6 +58,7 @@ public MainWindowViewModel() } }; + Source.Selection = new TreeDataGridCellSelectionModel(Source); MaxPopulation = _data.Max(x => x.Population); } diff --git a/TreeDataGrid/FlatTreeDataGridSample/Views/MainWindow.axaml b/TreeDataGrid/FlatTreeDataGridSample/Views/MainWindow.axaml index e6d4c96..406bbcf 100644 --- a/TreeDataGrid/FlatTreeDataGridSample/Views/MainWindow.axaml +++ b/TreeDataGrid/FlatTreeDataGridSample/Views/MainWindow.axaml @@ -18,6 +18,7 @@ Source="{Binding Source}" AllowTriStateSorting="True" AutoDragDropRows="True" + FrozenColumnCount="1" CellPrepared="countries_CellPrepared" CellClearing="countries_CellClearing"> diff --git a/TreeDataGrid/FlatTreeDataGridSample/readme.md b/TreeDataGrid/FlatTreeDataGridSample/readme.md index ed6c2d7..b79beaa 100644 --- a/TreeDataGrid/FlatTreeDataGridSample/readme.md +++ b/TreeDataGrid/FlatTreeDataGridSample/readme.md @@ -10,6 +10,7 @@ This `FlatTreeDataGridSource` sets up a grid which displays a list of countries ### Column Configuration - **Multiple Column Types**: The sample shows how to define different column types: + - A row header column for row numbers. Together with the `FrozenColumnCount` property, this keeps the row numbers visible during horizontal scrolling. - Read/write text columns with the `Country` name column - Template columns with custom cell and edit templates for the `Region` column - Read-only text columns for data like `Population` and `Area` @@ -26,6 +27,7 @@ This `FlatTreeDataGridSource` sets up a grid which displays a list of countries - **Column Header Styling**: Custom styling for specific column headers (last column appears in bold) - **Cell Styling**: Custom styling for specific cells (last column cells appear in bold) - **Custom Templates**: Both display and edit templates for the Region column, including a ComboBox for selection +- **Frozen Columns**: Keeping certain columns fixed during horizontal scrolling by setting `TreeDataGrid.FrozenColumnCount` ### Data Binding - Proper MVVM implementation showing how to bind a collection of domain objects (Countries) to the TreeDataGrid