Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Time format in datagridview

2 views
Skip to first unread message

bpsdgnews

unread,
Dec 23, 2009, 3:49:35 PM12/23/09
to
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?

Captain Jack

unread,
Dec 23, 2009, 4:10:41 PM12/23/09
to
"bpsdgnews" <dipp...@gmail.com> wrote in message
news:0447f1b8-94aa-41b4...@22g2000yqr.googlegroups.com...

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.

--
Jack


bpsdgnews

unread,
Dec 23, 2009, 4:47:14 PM12/23/09
to
On 23 dec, 22:10, "Captain Jack" <CaptainJack1...@comcast.net> wrote:
> "bpsdgnews" <dippi...@gmail.com> wrote in message

Thanks Jack,

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

Regards, Bas.

bpsdgnews

unread,
Dec 25, 2009, 4:09:35 PM12/25/09
to
> 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.

0 new messages