troubleshooting Question

DataGridView sorting of custom formated datetime column

Avatar of Sh4d1
Sh4d1Flag for Slovakia asked on
Visual Basic Classic.NET ProgrammingVisual Basic.NET
3 Comments1 Solution2967 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
60MXG

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros