.NET MAUI TreeDataGrid Columns Reordering
The .NET MAUI TreeDataGrid exposes a reordering feature allowing the user to drag and drop columns and change their order.
The following properties control the reordering feature:
CanUserReorderColumns(bool)—Defines whether the user can reorder theDataGridColumns. The default value istrue.ColumnReorderIndicatorTemplate(DataTemplate)—Defines the template that presents the indicator that is displayed between two columns during reordering.ColumnHeaderDragVisualTemplate(DataTemplate)—Specifies the template that presents the drag visual of the dragged column header.
Events
The TreeDataGrid inherits the following events related to the DataGrid reordering operation:
-
ColumnReorderStarting—Raised when the user starts to drag a column to reorder it. TheColumnReorderStartingevent handler receives the following parameters:- A
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
ColumnReorderStartingEventArgsobject, which has a reference to the following properties:Column(DataGridColumn)—Gets the column that will be reordered.Index(int) —Gets the index of the column that will be reordered. TheIndexis the index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofColumn.IsFrozen.Cancel(bool)—Defines a value indicating whether the reordering operation is canceled.
- A
-
ColumnReordering—Raised continuously while the column is being dragged. TheColumnReorderingevent handler receives the following parameters:- A
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
ColumnReorderingEventArgsobject, which has a reference to the following properties:Column(DataGridColumn)—Gets the column that will be reordered.OldIndex(int) —Gets the initial index of the column that is being reordered. TheOldIndexis the old index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofColumn.IsFrozen.NewIndex(int) —Gets the new potential index of the column that is being reordered. TheNewIndexis the new index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofNewIsFrozen.NewIsFrozen(bool)—Gets the new potentialTelerik.Maui.Controls.DataGrid.DataGridColumn.IsFrozenvalue of the column that is being reordered.CanDrop(bool)—Defines a value indicating whether dropping the column at this specific location is allowed. The default value istrue.
- A
-
ColumnReorderCompleting—Raised when the user drops the column. This doesn't mean the column is reordered. TheColumnReorderCompletingevent handler receives the following parameters:- A
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
ColumnReorderCompletingEventArgsobject, which has a reference to the following properties:Column(DataGridColumn)—Gets the column that is being reordered.OldIndex(int) —Gets the initial index of the column that is being reordered. TheOldIndexis the old index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofColumn.IsFrozen.NewIndex(int) —Gets the new potential index of the column that is being reordered. TheNewIndexis the new index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofNewIsFrozen.NewIsFrozen(bool)—Gets the new potentialTelerik.Maui.Controls.DataGrid.DataGridColumn.IsFrozenvalue of the column that is being reordered.IsDropAllowed(bool)—Gets a value that indicates whether the column was dropped at a valid location. A valid location means that the column has changed its index and/or the value of itsIsFrozenproperty and the drop at this location was not forbidden by setting theTelerik.Maui.Controls.DataGrid.ColumnReorderingEventArgs.CanDropproperty of theTelerik.Maui.Controls.DataGrid.ColumnReorderingEventArgstofalse. The default value istrue.Cancel(bool)—Defines a value indicating whether the reordering operation is canceled.
- A
-
ColumnReordered—Raised when a column has been successfully reordered. TheColumnReorderedevent handler receives the following parameters:- A
senderargument which is of typeobject, but can be cast to theRadDataGridtype. - A
ColumnReorderCompletingEventArgsobject, which has a reference to the following properties:Column(DataGridColumn)—Gets the column that has been reordered.OldIndex(int) —Gets the initial index of the column that has been reordered. TheOldIndexis the old index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofOldIsFrozen.OldIsFrozen(bool)—Gets the initialTelerik.Maui.Controls.DataGrid.DataGridColumn.IsFrozenvalue of the column that has been reordered.NewIndex(int) —Gets the new index of the column that has been reordered. TheNewIndexis the new index of the item inside theFrozenColumnsorUnfrozenColumnscollection, depending on the value ofColumn.IsFrozen.
- A
As the TreeDataGrid inherits from DataGrid, ror the runnable example representing the Drag Templates, see the SDKBrowser Demo Application and go to DataGrid > Columns.