|
| 1 | +--- |
| 2 | +title: Defining Columns |
| 3 | +page_title: .NET MAUI TreeDataGrid Documentation - Defining Columns |
| 4 | +description: Lear what are the configuration options you can apply to the columns in the TreeDataGrid for .NET MAUI. |
| 5 | +position: 0 |
| 6 | +slug: treedatagrid-columns-overview |
| 7 | +--- |
| 8 | + |
| 9 | +# .NET MAUI TreeDataGrid Defining Columns |
| 10 | + |
| 11 | +The [Telerik UI for .NET MAUI TreeDataGrid]({%slug treedatagrid-overview%}) inherits three approaches from the [DataGrid]({%slug datagrid-overview%}) that you can take to define different columns: |
| 12 | + |
| 13 | +* **Automatically**—by setting `AutoGenerateColumns` property to `True` (default value). |
| 14 | +* **Manually**—by adding columns to the DataGrid's `Columns` collection and setting the `AutoGenerateColumns` property to `False`. |
| 15 | +* **Mixed**—by adding columns to the `Columns` collection and also setting the `AutoGenerateColumns`to `True` (default value). |
| 16 | + |
| 17 | +## Automatic Columns Generation |
| 18 | + |
| 19 | +By default, the TreeDataGrid generates typed columns automatically based on the underlying data type. When, for example, you set the `ItemsSource` of the `RadDataGrid` to a collection of clubs (see the sample code below), the control will create a separate column for each public property of the `Club` object. |
| 20 | + |
| 21 | +For example, let's have a sample `Club` object: |
| 22 | + |
| 23 | +```XAML |
| 24 | +public class Club |
| 25 | +{ |
| 26 | + public string Name { get; set; } |
| 27 | + public DateTime Established { get; set; } |
| 28 | + public bool IsChampion { get; set; } |
| 29 | + public ObservableCollection<Club> Children { get; set; } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +With the automatic columns generation TreeDataGrid will create the following columns: |
| 34 | + |
| 35 | +* `DataGridTextColumn` for the `Name` property. |
| 36 | +* `DataGridDateColumn` for the `Established` property. |
| 37 | +* `DataGridBooleanColumn` for the `IsChampion` property. |
| 38 | +* `DataGridTypedColumn` for the `IsChampion` property. |
| 39 | + |
| 40 | +## Manual Columns Definition |
| 41 | + |
| 42 | +Using the built-in auto generation of columns does not fit all scenarios. In such cases you can manually define the needed columns. When defining a column you can choose between several column types: |
| 43 | + |
| 44 | +* [Text Column]({%slug datagrid-columns-text-column%})—Represents a column that converts the content of each associated cell to a System.String object. |
| 45 | +* [Numerical Column]({%slug datagrid-columns-numerical-column%})—Represents an extended `DataGridTextColumn` that presents numerical data (`int` and `double` types). |
| 46 | +* [Boolean Column]({%slug datagrid-columns-boolean-column%})—An extended `DataGridTextColumn` implementation that presents Boolean data. |
| 47 | +* [Date Column]({%slug datagrid-columns-date-column%})—An extended `DataGridTextColumn` that presents data of type `DateTime`. |
| 48 | +* [Time Column]({%slug datagrid-columns-time-column%})—Represents an extended `DataGridTextColumn` that presents the `TimeOfDay` of a `DateTime` type. |
| 49 | +* [ComboBox Column]({%slug datagrid-columns-picker-column%})—Represents an extended `DataGridTextColumn` which cell value editor is a Telerik.Maui.Controls.RadComboBox control. |
| 50 | +* [Template Column]({%slug datagrid-columns-template-column%})—Represents a column that uses a `DataTemplate` to describe the content of each associated grid cell. |
| 51 | +* [ToggleRowDetails Column]({%slug datagrid-columns-toggle-column%})—Represents a column that allows the user to show and hide the row details for an item. |
| 52 | + |
| 53 | +For the typed columns (Text, Numerical, Boolean, Date, Time and ComboBox) you can define which property of the underlying data object the column represents in the following ways: |
| 54 | + |
| 55 | +* `PropertyName`—Specifies the name of the property of the data object being displayed in the column's cells. |
| 56 | +* `DataMemberBinding`—Defines the binding which points to the data member of the underlying object being displayed in the column's cell. With `DataMemberBinding`, you have control over the way data is formatted and displayed in the DataGrid cells, for example you can add a string formatter or a value converter. |
| 57 | + |
| 58 | +> For a runnable example with the TreeDataGrid columns, see the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and go to the **TreeDataGrid > Getting Started** category. |
| 59 | +
|
| 60 | +## Columns Features |
| 61 | + |
| 62 | +Find below a quick overview of the TreeDataGrid's Columns features. |
| 63 | + |
| 64 | +### Column Headers |
| 65 | + |
| 66 | +The top cell of a column is called Header. Its purpose is to set a caption for the column, which describes the data displayed in it. The .NET MAUI TreeDataGrid provides fully customizable column headers, check [Column Headers]({%slug treedatagrid-column-header%}) for detailed information. |
| 67 | + |
| 68 | +### Columns Cell Templates |
| 69 | + |
| 70 | +The TreeDataGrid provides a set of predefined column types such as Text Column, Numerical Column, etc. In case you need to extend the functionality of a column, for example customize the default appearance or add more UI elements, use the exposed templates - `CellContentTemplate` and `CellEditTemplate`. For detailed information, see the [Columns Cells Templates]({%slug treedatagrid-cell-templates%}) topic. |
| 71 | + |
| 72 | +### Column Footers |
| 73 | + |
| 74 | +The TreeDataGrid allows you to display additional information which applies to the columns in a specific row placed at the bottom of the control. This row consists of individual footer cells for each column. Take a look at the [Column Footers]({%slug treedatagrid-column-footer%}) for detailed information. |
| 75 | + |
| 76 | +### Column Resizing |
| 77 | + |
| 78 | +Columns inside the Telerik .NET MAUI TreeDataGrid are resizable by default. The feature is available only on Desktop - WinUI and MacCatalyst. For more details see the [Column Resizing]({%slug datagrid-column-resizing%}) topic. |
| 79 | + |
| 80 | +### Columns Width |
| 81 | + |
| 82 | +The TreeDataGrid provides a flexible mechanism for setting columns' width through columns' `SizeMode` and `Width` properties. For more details see the [Columns Width]({%slug datagrid-columns-width%}) topic. |
| 83 | + |
| 84 | +### Frozen Columns |
| 85 | + |
| 86 | +You can pin a column on the left side of the TreeDataGrid by setting the `IsFrozen` property to the column. By default the value is `False`. When setting it to `True` to a concrete column, it makes the column frozen. For detailed information, see the [Frozen Columns]({%slug treedatagrid-frozen-columns%}) topic. |
| 87 | + |
| 88 | +### Columns Reordering |
| 89 | + |
| 90 | +The TreeDataGrid exposes a reordering feature allowing the user to drag and drop columns and change their order. For more details, see the [Columns Reordering]({%slug datagrid-columns-reordering%}) topic. |
| 91 | + |
| 92 | +>tip For an outline of all TreeDataGrid features review the [.NET MAUI TreeDataGrid Overview]({%slug treedatagrid-overview%}) article. |
| 93 | +
|
| 94 | +## See Also |
| 95 | + |
| 96 | +- [Column Headers]({%slug treedatagrid-column-header%}) |
| 97 | +- [Columns Cells Templates]({%slug treedatagrid-cell-templates%}) |
| 98 | +- [Column Footers]({%slug treedatagrid-column-footer%}) |
| 99 | +- [Column Resizing]({%slug treedatagrid-column-resizing%}) |
| 100 | +- [Columns Width]({%slug treedatagrid-columns-width%}) |
| 101 | +- [Frozen Columns]({%slug treedatagrid-frozen-columns%}) |
| 102 | +- [Columns Reordering]({%slug treedatagrid-columns-reordering%}) |
0 commit comments