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!
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.
Is there a way to always force the sort indicator to be ON for every column??
I can set all the columns to Ascending on the Initialize_Layout. The problem is as I choose 1 column to sort the column to the left of my sorted column drops the sort indicator.
Hm. I think you could try handling the BeforeSortChange event and then set the SortIndicator on every column.
I'm not sure I understand your question.
HeaderClickAction.ExternalSortSingle means that the grid will display a Sort Indicator in the column header, but the grid will not actually sort the data.
So if you are trying to remove sorting from the grid, you should be turning off sorting entirely by setting HeaderClickAction to None or Select.
If you want to sort the data, then the best thing to do is to sort the data in your data source before you bind it to the grid. Or, if you are changing the sort order after the grid is bound, you need to tell the grid to refresh itself after the sort is complete.
To refresh the grid, call:
grid.Rows.Refresh(ReloadData);
I would like to manually sort the Ultragrid.
I'd like to remove the sorting from the Header Column. I am using the following to remove sorting
e.Layout.Override.HeaderClickAction =
HeaderClickAction.ExternalSortSingle;
However, even if I call refreshSort() before binding the table to the grid,
I am unable to sort the grid.
Is there something that I am missing ?