System.TimeSpan formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys

I have a problem trying to format a TimeSpan value in a custom grid like I would format a DateTime (through a format string). It seems impossible, I always get the standard "hh:mm:ss" formatting insead of "hh:mm", for instance. Any ideas? Would appreciate your help

Cheers
Eugen
 
Eugen Gulinsky said:
I have a problem trying to format a TimeSpan value in a custom grid
like I would format a DateTime (through a format string). It seems
impossible, I always get the standard "hh:mm:ss" formatting insead of
"hh:mm", for instance. Any ideas? Would appreciate your help.

Unfortunately there's no format specifier for a TimeSpan. You could
use:

string hourMinute = String.Format("{0:n2}:{0:n2}", ts.Hours,
ts.Minutes);

(Untested, but you get the idea._
 
Hi

thx for the idea but it wouldn't help because I need the TimeSPan to be formatted automatically through a format string; this is happening in a grdi column. I have a custom edit control which shows the right hh:mm format but I see no way to format its string representation..

Cheers
Eugen
 
Eugen Gulinsky said:
thx for the idea but it wouldn't help because I need the TimeSPan to
be formatted automatically through a format string; this is happening
in a grdi column. I have a custom edit control which shows the right
hh:mm format but I see no way to format its string representation...

No, it's not going to work like that, I'm afraid :(

I suspect you'll find there's *some* way of formatting values in an
arbitrary fashion (just as booleans end up as checkboxes) but it may
well be more effect than you want to go to.

One alternative might be to hide the "real" grid column and have
another column which is set using row/column changes (i.e. it's
computed, but in a more complex way than just using an expression).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top