Skip to content
Ira
Ira asked on Oct 25, 2017 11:49 AM

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.

Sign In to post a reply

Replies

  • 0
    Ira
    Ira answered on Oct 21, 2017 11:37 PM

    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.

    • 0
      Plamena Miteva
      Plamena Miteva answered on Oct 23, 2017 10:08 AM

      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.

      • 0
        Ira
        Ira answered on Oct 23, 2017 11:57 PM

        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). 

      • 0
        Plamena Miteva
        Plamena Miteva answered on Oct 24, 2017 1:51 PM

        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.

      • 0
        Ira
        Ira answered on Oct 24, 2017 6:47 PM

        Works great

        Thanks very much, much appreciated.

      • 0
        Georgia
        Georgia answered on Oct 25, 2017 11:49 AM

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

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Ira
Favorites
0
Replies
6
Created On
Oct 25, 2017
Last Post
8 years, 10 months ago

Suggested Discussions

Tags

Created by

Ira

Created on

Oct 25, 2017 11:49 AM

Last activity on

Oct 25, 2017 11:49 AM