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?
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 IfEnd If
John.
You could also use the BeforeSortChange event and examine the e.SortedColumns and if any columns exist in the collection that you do not want to allow sorting on, you set e.Cancel to true.