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
490
sort string column
posted

hi ,

i have ultraGrid ,the grid dataSource binding from list of object like the follwing :

List<Stock>  list = new List<Stock> ;

ultraGrid1.DataSource = list ;

Calss Stock {

 private string Price;

private string Volume}

i did the follwing things in InitializeLayout:

e.Layout.Bands[0].Columns[

"Price"].Style = ColumnStyle.Double;

 e.Layout.Bands[0].Columns["Volume"].Style = ColumnStyle.Double;

--------------------my Quistion is -------------------------

when I click to sort the Volume cloumn or price column the sorting not correct .

Parents
No Data
Reply
  • 17259
    Verified Answer
    Offline posted

    I assume setting style isn't relevant for sorting. Since your data is a string, it compares like a string. If you can edit your class, create two properties of type double that will cast the original properties and show only them in the grid. If you can't, you can create your own sort comparer an set it as the column.SortComparer.

    public class GridCellComparer : IComparer<UltraGridCell>, IComparer

    {

    #region IComparer<UltraGridCell> Members

     

    public int Compare(UltraGridCell x, UltraGridCell y)

    {

    IComparable xValue = double.Parse((string)x.Value);

    IComparable yValue = double.Parse((string)y.Value);

     

    if (xValue != null && yValue != null)

    return xValue.CompareTo(yValue);

     

    return x.Text.CompareTo(y.Text);

    }

     

    #endregion

     

    #region IComparer Members

     

    public int Compare(object x, object y)

    {

    return Compare(x as UltraGridCell, y as UltraGridCell);

    }

     

    #endregion

    }

Children