Articles in this section
Category / Section

How can I restrict the sorting of the particular column on Header click ?

1 min read

 

We can dynamically set the SortBehavior in the CellClick event (or CellDoubleClick event) to restrict the sorting of a particular column. Please refer the following code snippet to set the SortBehavior of a particular Column.

C#

this.gridDataBoundGrid1.CellClick += new GridCellClickEventHandler(gridDataBoundGrid1_CellClick);

private void gridDataBoundGrid1_CellClick(object sender, GridCellClickEventArgs e)

{

if((e.ColIndex == 1 || e.ColIndex == 3)

//sort only 1 & 3

&& e.RowIndex == 0)

this.gridDataBoundGrid1.SortBehavior = GridSortBehavior.SingleClick;

else

this.gridDataBoundGrid1.SortBehavior = GridSortBehavior.None;

}

VB

Private Sub GridDataBoundGrid1_CellClick(ByVal sender As System.Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs) Handles GridDataBoundGrid1.CellClick

''sort only 1 & 3

If (e.ColIndex = 1 OrElse e.ColIndex = 3) AndAlso e.RowIndex = 0 Then

Me.GridDataBoundGrid1.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.SingleClick

Else

Me.GridDataBoundGrid1.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.None

End If

End Sub

Sample :

http://websamples.syncfusion.com/samples/KB/GDBC_Sort/main.htm

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied