VGridOptionsBehavior.AllowSort Property
Gets or sets whether users can sort data in the control.
Namespace: DevExpress.XtraVerticalGrid
Assembly: DevExpress.XtraVerticalGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid
Declaration
[DefaultValue(true)]
[XtraSerializableProperty]
public virtual bool AllowSort { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Boolean | true | true if users can sort data in the control; otherwise, false |
Property Paths
You can access this nested property as listed below:
Object Type | Path to AllowSort |
---|---|
VGridControlBase |
|
Remarks
A user can sort data in the control from a row header’s context menu. Right-click a row header and select Sort Ascending or Sort Descending to sort values in the corresponding order. To make all rows display data in the same order as the data source, select Clear Sorting.
You can set the AllowSort
property to false to disable this functionality.
Sort with a Click on a Row Header
You can enable the control’s AllowSortOnClick option to sort data when users click on a row header. Consecutive clicks change the sort order. Ctrl+Click clears the sort. If the AllowSort
option is disabled, this property is not in effect.
If the control’s AllowSortOnClick option is enabled, you can use a row’s AllowSortOnClick property to disable this functionality for the row.
Sort in Code
Use a row’s SortOrder property to specify whether the row is sorted in ascending or descending order. If this property is set to None, data is not sorted. To make all rows display data in the same order as the data source, call the ClearSorting() method.
Sort by Multiple Rows
Data in the control can be sorted by multiple rows. For example, in a list of employees, you can first sort employees by surname and then by name. The resulting order of records depends on which list is sorted first. Users can hold Shift and click headers to sort by multiple rows.
A row’s SortIndex property specifies the index of the row in the collection of rows by which data is sorted. If you assign a non-negative value to this property, the control inserts the row to the collection of sorted rows at the specified position and sorts data in the row in ascending order.
When a user sorts data or you change a row’s SortOrder or SortIndex property value, the control raises the StartSorting event. When data is sorted, the EndSorting event fires.
Prevent Multiple Updates
Each time the sort order changes, the control reloads data from the data source. If you sort data by multiple rows, use the BeginSort() and EndSort() methods to prevent multiple updates. These methods suppress the StartSorting and EndSorting events.
Localize Context Menu Commands
You can use localizer objects to change captions of the control’s context menu commands. To do this, create a VGridLocalizer descendant, and override its GetLocalizedString method.
You can also use satellite assemblies to localize the control. See the following topic for more information: Localization.
Example
The code below allows users to click a row header to sort data in all rows except the ID row.
vGridControl.OptionsBehavior.AllowSort = true;
vGridControl.OptionsBehavior.AllowSortOnClick = true;
erID.Properties.AllowSortOnClick = DefaultBoolean.False;