From: bpsdgnews on
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?
From: Captain Jack on
"bpsdgnews" <dippides(a)gmail.com> wrote in message
news:0447f1b8-94aa-41b4-b7d6-563ef5384757(a)22g2000yqr.googlegroups.com...
> 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.

--
Jack


From: bpsdgnews on
On 23 dec, 22:10, "Captain Jack" <CaptainJack1...(a)comcast.net> wrote:
> "bpsdgnews" <dippi...(a)gmail.com> wrote in message
>
> news:0447f1b8-94aa-41b4-b7d6-563ef5384757(a)22g2000yqr.googlegroups.com...
>
> > 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.
>
> --
> Jack

Thanks Jack,

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

Regards, Bas.
From: bpsdgnews on
On 23 dec, 22:47, bpsdgnews <dippi...(a)gmail.com> wrote:
> On 23 dec, 22:10, "Captain Jack" <CaptainJack1...(a)comcast.net> wrote:
>
>
>
>
>
> > "bpsdgnews" <dippi...(a)gmail.com> wrote in message
>
> >news:0447f1b8-94aa-41b4-b7d6-563ef5384757(a)22g2000yqr.googlegroups.com...
>
> > > 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.
>
> > --
> > Jack
>
> 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.