Guy Barrette, Microsoft, Regional Director, Montreal, Canada, Visual Studio, .NET Expertise Infragistics WinGrid Sort - Guy Barrette

Guy Barrette

Microsoft Regional Director, Montreal, Canada

Infragistics WinGrid Sort

I was trying to sort an Infragistics WinGrid automatically after each row insert or update by the user so in the AfterRowUpdate event, I added the following code:

grd.DisplayLayout.Bands[0].Columns["MyColumn"].SortIndicator = Infragistics.Win.UltraWinGrid.SortIndicator.Ascending;
grd.DisplayLayout.Bands[0].Columns["MyColumn"].Band.SortedColumns.RefreshSort(true);
grd.Refresh();

This works fine except that the grid does an alphabetical sort even thought the column type is numeric.  Ex:
1
10
2
22
3

A quick search lead me to this Infragistics knowledge base article:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7695

Although not exactly what I wanted, I slightly changed to code to sort my numeric column.

public class srtComparer : IComparer
{
    public srtComparer()
    {}

    public int Compare(object x, object y)
    {
        UltraGridCell xCell = (UltraGridCell)x;
        UltraGridCell yCell = (UltraGridCell)y;
        return Decimal.Compare((Decimal)xCell.Row.Cells["MyColumn"].Value, (Decimal)yCell.Row.Cells["MyColumn"].Value);
        }
}

grd.DisplayLayout.Bands[0].Columns["MyColumn"].SortComparer = new srtComparer();
grd.DisplayLayout.Bands[0].Columns["MyColumn"].SortIndicator = Infragistics.Win.UltraWinGrid.SortIndicator.Ascending;
grd.DisplayLayout.Bands[0].Columns["MyColumn"].Band.SortedColumns.RefreshSort(true);
grd.Refresh();

Of course, the above class could be made more generic by having a column name or number as an argument.

I would have expected that the grid would sort correctly depending on the column type but I guess this behaviour gives more flexibility.

Posted: Nov 21 2008, 09:44 AM by guybarrette | with 2 comment(s)
Filed under:

Comments

Kaviraj said:

Hi is there a way to sort columns based on a particular parent row on a band.. this sort shouldnt affect the other child bands of the remaining parent rows.

# September 9, 2009 2:07 AM

AK said:

Thanks it solved my problem!

# May 10, 2011 10:11 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)