Time format in datagridview

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?
 
B

bpsdgnews

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.
 
B

bpsdgnews

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.
 

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

Top