We help IT Professionals succeed at work.

DataGridView sorting of custom formated datetime column

2,959 Views
Last Modified: 2013-12-25
Hello Experts,

I have problem with sorting of one column. I have datagridview that is populated from dataset. It has one column named TimeInState, in it I need to show easy readeable period of time from last change. The input value from dataset is string in format 'MM/dd/yyyy hh:mm:ss'.

I use DataGridView CellFormatting event where i parse this string to DateTime and after that i made Substract to TimeSpan and from it, it create custom formated 'Time in State' text (it show how long is ticket there) like this '19 days,3 hours,56 min,31 sec'.

Everything work great except sorting. When i click on header and try to sort column it sort it like text and I need to sort it like DateTime.

I read that i can use ColumnSortModeChanged Event but i dont know how.

I hope that my question is clear :).

Thanks for any suggestion.
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry for late reply, i was on vacation... But your links help, thanks.

Author

Commented:
Thanks.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.