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
436
Turn Off Column Sort Indicator
posted

Hi,

I am looking for a way to turn off the display of the Sort Indicator on a sorted column while retaining the ability for the user to sort the column.

I have searched the forum and found a similar question - the suggested fix was to use a CreationFilter on the grid to cancel the creation of the SortIndicatorUIElement.

This does stop the indicator being displayed - however my problem is that the space is still made for the indicator anyway. How do I prevent this?

This results in wrapping of the header text unless I resize the column to fit the updated column header.

I have very strict (and unique!) requirements to save as much space as possible to resizing the column is not an option. I need to hide the indicator AND stop the grid reserving space for it also.

I have tried numerous workarounds involving resetting the columns SortIndicator property to None. This does the trick when sorting Ascending however when sorting Descending it reverts the sort to Ascending :-(

 Any suggestions are most welcome.


Thanks!

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi,

    One way you might be able to do this is to take advantage of the fact that when you set the SortIndicator on the column to None, the grid does not un-sort the column. So if you set the SortIndicator to Ascending, then force the grid to paint, you can then set the SortIndicator back to none to remove the indicator, while the column remains sorted. 

    Something like this:


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                e.Layout.Override.HeaderClickAction = HeaderClickAction.Select;
                e.Layout.Override.SelectTypeCol = SelectType.None;
            }

            private void ultraGrid1_MouseUp(object sender, MouseEventArgs e)
            {
                // Get the grid.
                UltraGrid grid = (UltraGrid)sender;

                // Get the last UIElement entered by the mouse.
                UIElement element = grid.DisplayLayout.UIElement.LastElementEntered;

                // Try to get a column header.
                Infragistics.Win.UltraWinGrid.ColumnHeader columnHeader = element.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader;
                if (columnHeader != null)
                {
                    // Get the last sort direction of the column from the tag property on the
                    // column header.
                    SortIndicator? sortIndicator = columnHeader.Tag as SortIndicator?;

                    // Toggle to sorting.
                    switch (sortIndicator)
                    {
                        case SortIndicator.Descending:
                        case null:
                            sortIndicator = SortIndicator.Ascending;
                            break;
                        case SortIndicator.Ascending:
                            sortIndicator = SortIndicator.Descending;
                            break;
                    }

                    // Store the new sort direction in the tag. This is so we can clear the
                    // SortIndicator property on the column, but still remember which direction
                    // the column was last sorted.
                    columnHeader.Tag = sortIndicator;

                    // Get the column.
                    UltraGridColumn column = columnHeader.Column;

                    // Force the grid to sort.
                    column.SortIndicator = (SortIndicator)sortIndicator;
                    column.Band.SortedColumns.RefreshSort(true);
                    column.Band.Layout.Grid.Refresh();

                    // Un-sort.
                    column.SortIndicator = SortIndicator.None;
                }
            }

    There are a couple of caveats, though.

    1) The grid sorts lazily. This means that in order to sort the grid, you will have to force it to paint while the SortIndicator is set. This is easy enough to do, but it means there will be a little flicked in the column header while the sort indicator appears and then disappears. To get around this, you can probably use the same CreationFilter you referred to here.

    2) Since the SortIndicator on the column is getting cleared, you will need to remember which columns are sorted and in what direction. In my sample code here, I use the Tag property on the column header. But my implementation here is incomplete. I did not, forexample, clear the tag of all of the other columns when you sort a column. I also didn't attempt to deal with multi-column sorting. 

Children