Objective Grid for Microsoft .NET allows you to sort a grid by either columns or rows. This section demonstrates how to enable sorting. See also (Section 3.7.4, "Sorting," for information on how you can customize Objective Grid for Microsoft .NET to enable other sorting-related features.)
The Sort_CS tutorial, which is located in the Tutorials subdirectory of your Objective Grid for Microsoft .NET installation directory, shows how to support sorting when users double-click row or column headers.
Replace the FormLoad() method with the following code:
private void FormLoad(object sender, System.EventArgs e) { gridControl1.RowCount = 10; gridControl1.ColCount = 10; Random r = new Random(); for( int i = 1; i <= gridControl1.RowCount; ++i ) { for( int j = 1; j <= gridControl1.ColCount; ++j ) { gridControl1[i,j].Style.Value = "" + r.Next(30); } } } |
Build and run the application.
In the Form Designer, click the grid and view the grid properties.
Locate the EnableHorizontalSorting and EnableVerticalSorting properties in the Data property group. Set these properties to true.
Build and run the application.
Double-click the column header labeled "A." The rows are sorted in ascending order based on each row's value in column "A." Figure 27 shows the result.
Double-click the column header again to resort the values in descending order.
You can programmatically control whether or not the rows or columns can be sorted. Assuming the grid object is called gridControl1:
gridControl1.Param.EnableHorizontalSorting = true; gridControl1.Param.EnableVerticalSorting = false; |
This code fragments allows rows to be sorted and disallows sorting for columns.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.