Avatar of Sh4d1
Sh4d1
Flag for Slovakia asked on

DataGridView sorting of custom formated datetime column

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.
Visual Basic ClassicVisual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Sh4d1

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
60MXG

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Sh4d1

ASKER
Sorry for late reply, i was on vacation... But your links help, thanks.
Sh4d1

ASKER
Thanks.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck