GridViewDataColumn DataType not sorting correctly

3 posts, 1 answers
  1. Michael
    Michael avatar
    11 posts
    Member since:
    May 2013

    Posted 14 Jun 2013 Link to this post

    I have a gridview that is built from a collection of records. I set the datatype of each column, and I can confirm that the datatype is correct in the gridview itself (by checking in debug). That being said, when I sort on certain numeric type columns - the grid is treating it as a string. Am I missing some kind of property? Here is my code. 

    var columns = mainViewModel.Records.First()
                    .Properties
                    .Select((x, i) => new { Name = x.Name, DataType = x.DataType, Index = i })
                    .ToArray();
     
     
                foreach (var column in columns)
                {
                    var binding = new Binding(string.Format("Properties[{0}].Value", column.Index));
     
                    GridViewDataColumn col = new GridViewDataColumn();
                     
                    col.UniqueName = column.Name;
                    col.Header = column.Name;
                    col.DataMemberBinding = binding;                                   
                    col.DataType = column.DataType;               
                    col.IsSortable = true;               
     
                    fleetGrid.Columns.Add(col);
                }
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jun 2013 Link to this post

    Hello,

    Would you please share what is the type of the "Properties[{0}].Value" property? If it is string, then the data will be sorted as string no matter what type you specify for the DataType. If it is of type object, then it will be sorted correctly based on the DataType you have set.
     

    Regards,
    Didie
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Michael
    Michael avatar
    11 posts
    Member since:
    May 2013

    Posted 17 Jun 2013 Link to this post

    Well that answers that question... The  "Properties[{0}].Value" is a string. I guess I was under the assumption that I could in effect "cast" it into a GridViewDataColumn DataType - guess not. Thanks for the help!
Back to Top