Sort in code only

Answered (Verified) This post has 1 verified answer | 6 Replies | 3 Followers Thread's RSS feed.

IraGladnick
Points 155
Replied On: Sat, Oct 21 2017 4:56 PM Reply

How can you sort on one or more columns in code without displaying the column header sort indicators?

In the band override, I am currently doing the following:

        HeaderClickAction = HeaderClickAction.Select

       .SelectTypeCol = SelectType.None

I am also setting the SortIndicator for each column to SortIndicator.None

This hides the column header sort indicators, and prevents sorting by clicking on a column header.  But as soon as I add columns programmatically to the the band SortedColumns collection, the column header sort indicator for those columns gets displayed.  The sort indicators are disabled, but I would prefer that they didn't appear at all.

I also need to sort on a hidden column.  Adding a hidden column to the SortedColumns collection doesn't appear to have any effect on the sort order.


  • Post Points: 5

Verified Answer

Plamena Miteva
Points 1,935
Infragistics Employee
Answered (Verified) Replied On: Tue, Oct 24 2017 8:51 AM Reply
Verified by IraGladnick

Hello Ira,


When the columns are added to the SortedColumns collection, the grid automatically displays the sort indicators. The easier way to not display them would be to use CreationFilter.


I have modified the sample to demonstrate that approach. So now, when the ‘Sort Id’ button is clicked, the grid is sorted first by the values in the ‘Product’ column and then by the ‘Id’ column. The RemoveSortIndicatorCreationFilter removes the SortIndicatorUIElement from the headers.

Plamena Miteva

Entry Level Software Developer 

Infragistics, Inc.

  • Post Points: 55

All Replies

IraGladnick
Points 155
Replied On: Sat, Oct 21 2017 6:37 PM Reply

I was wrong about not being able to sort on a hidden column, that was actually just a side-effect of something else.  So please ignore that part of my inquiry.

I just need to find out how to get rid of the column sort indicators when sorting via code.

  • Post Points: 20
Plamena Miteva
Points 1,935
Infragistics Employee
Replied On: Mon, Oct 23 2017 5:08 AM Reply

Hello Ira,


You can set the SortIndicator property to none after adding the column to the SortedColumns collection.

I have created a sample project with an UltraGrid that has three columns including a hidden one. When the ‘Sort Id’ button is clicked the ‘Id’ column is sorted and the sort indicator is not visible after that. Respectively when the ‘Sort Hidden’ button is clicked the grid is sorted by the values in the hidden column.

Plamena Miteva

Entry Level Software Developer 

Infragistics, Inc.

  • Post Points: 20
IraGladnick
Points 155
Replied On: Mon, Oct 23 2017 6:57 PM Reply

Thanks for the sample.

Modifying the sample a bit, I see where my problem is likely related to the fact that I am actually sorting on multiple columns.

Say you change the button1 click event in your sample project to this:

    private void button1_Click(object sender, EventArgs e)
        {          
            UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0];
            band.SortedColumns.Add("Product", false, false);
            band.SortedColumns.Add("Id", false, false);
            band.Columns["Product"].SortIndicator = SortIndicator.None;
            band.Columns["Id"].SortIndicator = SortIndicator.None;
        }

If you now run the test project and click Button1, you will see that the rows are sorted only by the Id column.  But if you comment out the lines that set SortIndicator to SortIndicator.None, the sorting works properly:  sorted first by Product, and then by Id.

Fiddling around a bit, I found that if you reverse the order in which SortIndicator is assigned to SortIndicator.None such that you first set the SortIndicator on the Id column followed by setting SortIndicator on the Product column, clicking Button1 sorts things properly (first by Product, then by Id).

This seems to imply that setting SortIndicator to SortIndicator.None needs to be done in the reverse order in which columns are added to the SortedColumns collection.  But when I tried that in my own project, it didn't seem to make a difference.

Is there something special I need to be doing to properly support sorting on multiple columns in code, such that setting SortIndicator to SortIndicator.None doesn't interfere with the sort?

My project is pretty complicated, but if necessary I could try to put together a simplified version that shows the problem.  Just let me know if this is necessary. 

I'm setting the multi-column sort order in the AfterCellUpdate event, in case that makes a difference.  I'm also sorting on a total of four columns (some in descending order, some in ascending order). 

  • Post Points: 20
Plamena Miteva
Points 1,935
Infragistics Employee
Answered (Verified) Replied On: Tue, Oct 24 2017 8:51 AM Reply
Verified by IraGladnick

Hello Ira,


When the columns are added to the SortedColumns collection, the grid automatically displays the sort indicators. The easier way to not display them would be to use CreationFilter.


I have modified the sample to demonstrate that approach. So now, when the ‘Sort Id’ button is clicked, the grid is sorted first by the values in the ‘Product’ column and then by the ‘Id’ column. The RemoveSortIndicatorCreationFilter removes the SortIndicatorUIElement from the headers.

Plamena Miteva

Entry Level Software Developer 

Infragistics, Inc.

  • Post Points: 55
IraGladnick
Points 155
Replied On: Tue, Oct 24 2017 1:47 PM Reply

Works great

Thanks very much, much appreciated.

  • Post Points: 5
Georgia
Points 5
Replied On: Wed, Oct 25 2017 6:49 AM Reply

you really did a tremendous job by authentic reply, I had a same issue so, Thanks dude

  • Post Points: 5
Page 1 of 1 (7 items) | RSS