Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Enable sorting only on a specific column
posted

 Hi..I'm having a hard time disabling sorting in the WinGrid. I want to enable the sorting only one one column. I set up HeaderClickAction = SortSingle. I add the column on which I want to enable sorting like this: SortedColumns.Clear() and then SortedColumns.Add("column_name"). What doesn't go right is that the arrows for sorting disappear, but if i click the headers the grid performs the search on all columns. What is wrong?

Parents
No Data
Reply
  • 880
    Suggested Answer
    posted

    Hi, the SortedColumns collection tells the grid which columns you are currently sorting on, not which columns you can sort on.

    I've had to do something similar and the only way I could find to do it was to handle the MouseEnterElement event and change the DisplayLayout.Override.HeaderClickAction property whenever the mouse entered a Header UI Element.

    Code similar to the following should do the trick:

    Dim headerUI As HeaderUIElement = CType(e.Element.GetAncestor(GetType(HeaderUIElement)), HeaderUIElement)
    If headerUI IsNot Nothing AndAlso headerUI.Header.Column IsNot Nothing Then
     If headerUI.Header.Column.Index = ColumnIWantToSort Then
      MyGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortSingle
     Else
      MyGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select
     End If
    End If

    John.

Children