I have a Datetime field I want to place in a grid column but I want to display the datetime value using a very special format that would not be good for sorting.
How can I display one thing and yet sort on the original datatype of the column? List Object attribute would be datetime, display value would be string on steroids.
Using the Format property of the column is a good way to do it, assuming you can format the data how you want it using the built-in DotNet numeric formatting.
If you need to do more complex formatting and therefore need to display the dates as strings, then what I would do is use a SortComparer on the column. You could examine the string, convert it into a date and then compare based on the actual dates instead of the strings.
Can I assume that I should bind the grid to my "formatted" column of type string and them hook in via the SortComparer and actually reference the bound object's true datetime column for sorting purposes? This makes sense to me thus I will try it.
Thanks.
Hi,
Since your question was about the sorting, I assumed you had already gotten the data displayed. So let's back up a bit.
What is the data type of the data in your data source?
If it's a DateTime, and you want to format the values in the grid, then you can simply bind the grid to your data source and you have a couple of ways you can go.
I did the SortComparer on the column. This worked the best as I have some weird requirements regarding the display of my DateTime? variable. Thanks for the time and options.