This sample demonstrates how to sort tables by different columns and also how to avoid sorting. This sample uses a hierarchical data set with two tables named "Customers" and "Orders." The data set will be created at design time. The sample includes options to sort the table’s content by contact name, city, and country.
Features:
Uses a hierarchical data set with two tables named "Customers" and "Orders"
Data set created at design-time
Includes options to sort the table’s content by contact name, city, and country
Demonstrates different ways to avoid sorting:
By setting the AllowSortColumns property to false and avoiding sorting on particular columns
Sorting on specified columns can also be prevented by handling the TableControlQueryAllowSortColumn event.
It also adds up the feature of aligning the sort icon on three alignments:
By default, the sort icon is placed at the Right.
Using the feature, the icon could be aligned in left side, right side or at the center.
Here is the code to sort the values by country:
this.gridGroupingControl1.Engine.TableDescriptor.SortedColumns.Add("Country", ListSortDirection.Ascending);
Here is the code to reset the sorted columns:
this.gridGroupingControl1.Engine.TableDescriptor.ResetSortedColumns();
This sample also demonstrates different ways to avoid sorting. One way is by setting the AllowSortColumns property to false and avoiding sorting on particular columns.
Here is the code for this:
this.gridGroupingControl1.TableOptions.AllowSortColumns=false;
Sorting on specified columns can also be prevented by handling the TableControlQueryAllowSortColumn event.
Here is a code snippet:
private void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridQueryAllowSortColumnEventArgs e) { if(e.Column.GetName() == "Region") { e.AllowSort=false; } }
This sample also demonstrates different ways to align the sorting cursor at various positions.
Here is the code for this:
this.gridGroupingControl1.SortIconPlacement = SortIconPlacement.Left;this.gridGroupingControl1.SortIconPlacement = SortIconPlacement.Top;this.gridGroupingControl1.SortIconPlacement = SortIconPlacement.Right;