Time format in datagridview

  • Thread starter Thread starter bpsdgnews
  • Start date Start date
B

bpsdgnews

Hi,

I'm putting data from an SQLserver database in a datagridview by
making use of a stored procedure.

There's a time field in there that has decimal places to the seconds.

But even when I do this:

grd.Columns("time").DefaultCellStyle.Format = "HH:mm:ss"

The datagridview still shows something like: 01:13:54.360000

How can I make it to only show whole seconds?
 
I've had trouble with the DefaultCellStyle property before... I've never
been sure that the grid creates a new and separate instance for each column.
I've had better luck with making a complete new object, and assigning that.

You might try something like this:

' Create a new style object from the grid's master style
Dim TimeStyle As New DataGridViewCellStyle(grd.DefatulCellStyle)
' Set the format property
TimeStyle.Format = "HH:mm:ss"
' Assign the style to the column
grd.Columns("time").DefaultCellStyle = TimeStyle

I haven't worked with the Time SQL type yet, but you may have better luck
with your cell style that way.

Thanks Jack,

But it didn't work. Same result as before.

Regards, Bas.
 
Thanks Jack,

But it didn't work. Same result as before.

Regards, Bas.- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

Okay,

I fixed it now by putting my custom format in the CellFormatting event.
 
Back
Top