473,414 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Showing Time in Grid

How do I get a datetime field from a database to show just
time in the datagrid. The default just shows date.

Thank you

Sebastian
Nov 20 '05 #1
6 2954
Hi Sebastian,

Initialize the FormatInfo property for the corresponding DataGridColumnStyle
with a pre-created DateTimeFormatInfo instance. You can probably achieve the
same effect by playing just with the DataGridColumnStyle.Format property (if
an existing time-only format exists or can be specified with a tailormade
format string).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <sS*********@ilogic.com> wrote in message
news:05****************************@phx.gbl...
How do I get a datetime field from a database to show just
time in the datagrid. The default just shows date.

Thank you

Sebastian


Nov 20 '05 #2
I don't know where your getting FormatInfo property from
but it doesn't exist for DataGridTableStyle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableStyle.GridColumnStyles
and it had no formating property.

Can someone advice how I get to this format property?

Thank you,

Seb

-----Original Message-----
Hi Sebastian,

Initialize the FormatInfo property for the corresponding DataGridColumnStylewith a pre-created DateTimeFormatInfo instance. You can probably achieve thesame effect by playing just with the DataGridColumnStyle.Format property (ifan existing time-only format exists or can be specified with a tailormadeformat string).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <sS*********@ilogic.com> wrote in messagenews:05****************************@phx.gbl...
How do I get a datetime field from a database to show just time in the datagrid. The default just shows date.

Thank you

Sebastian


.

Nov 20 '05 #3
Sebastian,

You just haven't dug deep enough :-) The GridColumnStyles collection is just
the right direction to pursue, and the next step would get you just where
you want to be. See below.

FormatInfo is set on System.Windows.Forms.DataGridColumnStyle class. This is
actually an abstract class, and has two implementations by default -
DataGridTextBoxColumn and DataGridBoolColumn. As both of these classes
inherit from DataGridColumnStyle, they obviosuly have Format and FormatInfo
properties you can customize to achieve a desirable data format.

And the GridColumnStyles collection contains just these
DataGridTextBoxColumns and DataGridBoolColumns. Unfortunately, when the
columns are generated automatically, you cannot access the column style
instances created behind the scenes. Therefore, you will need to specify a
set of columns manually, and it is easily done with the GridColumnStyles
collection designer.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <sS*********@ilogic.com> wrote in message
news:1b*****************************@phx.gbl...
I don't know where your getting FormatInfo property from
but it doesn't exist for DataGridTableStyle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableStyle.GridColumnStyles
and it had no formating property.

Can someone advice how I get to this format property?

Thank you,

Seb

-----Original Message-----
Hi Sebastian,

Initialize the FormatInfo property for the corresponding

DataGridColumnStyle
with a pre-created DateTimeFormatInfo instance. You can

probably achieve the
same effect by playing just with the

DataGridColumnStyle.Format property (if
an existing time-only format exists or can be specified

with a tailormade
format string).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <sS*********@ilogic.com> wrote in

message
news:05****************************@phx.gbl...
How do I get a datetime field from a database to show just time in the datagrid. The default just shows date.

Thank you

Sebastian


.


Nov 20 '05 #4
Ok. Can you give me some sample code on how to do this.
I'll attach some code I have so far so you can add the
rest to get the formatting code

GRID.TableStyles(rownum).GridColumnStyles("Date"). ..

Thank you,

Sebastian
-----Original Message-----
Sebastian,

You just haven't dug deep enough :-) The GridColumnStyles collection is justthe right direction to pursue, and the next step would get you just whereyou want to be. See below.

FormatInfo is set on System.Windows.Forms.DataGridColumnStyle class. This isactually an abstract class, and has two implementations by default -DataGridTextBoxColumn and DataGridBoolColumn. As both of these classesinherit from DataGridColumnStyle, they obviosuly have Format and FormatInfoproperties you can customize to achieve a desirable data format.
And the GridColumnStyles collection contains just these
DataGridTextBoxColumns and DataGridBoolColumns. Unfortunately, when thecolumns are generated automatically, you cannot access the column styleinstances created behind the scenes. Therefore, you will need to specify aset of columns manually, and it is easily done with the GridColumnStylescollection designer.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <sS*********@ilogic.com> wrote in messagenews:1b*****************************@phx.gbl...
I don't know where your getting FormatInfo property from
but it doesn't exist for DataGridTableStyle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableStyle.GridColumnStyles
and it had no formating property.

Can someone advice how I get to this format property?

Thank you,

Seb

>-----Original Message-----
>Hi Sebastian,
>
>Initialize the FormatInfo property for the
corresponding DataGridColumnStyle
>with a pre-created DateTimeFormatInfo instance. You can

probably achieve the
>same effect by playing just with the

DataGridColumnStyle.Format property (if
>an existing time-only format exists or can be specified

with a tailormade
>format string).
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Test Studio
>http://x-unity.miik.com.ua/teststudio.aspx
>Bring the power of unit testing to VS .NET IDE
>
>"Sebastian Santacroce" <sS*********@ilogic.com> wrote
in message
>news:05****************************@phx.gbl...
>> How do I get a datetime field from a database to show

just
>> time in the datagrid. The default just shows date.
>>
>> Thank you
>>
>> Sebastian
>
>.
>


.

Nov 20 '05 #5
> GRID.TableStyles(rownum).GridColumnStyles("Date"). ..

Here's an example from the "DataGridTableStyle Class" topic in MSDN:

Private Sub AddCustomDataTableStyle()
' Create a new DataGridTableStyle and set
' its MappingName to the TableName of a DataTable.
Dim ts1 As New DataGridTableStyle()
ts1.MappingName = "Customers"

' Add a GridColumnStyle and set its MappingName
' to the name of a DataColumn in the DataTable.
' Set the HeaderText and Width properties.

Dim boolCol As New DataGridBoolColumn()
boolCol.MappingName = "Current"
boolCol.HeaderText = "IsCurrent Customer"
boolCol.Width = 150
ts1.GridColumnStyles.Add(boolCol)

' Add a second column style.
Dim TextCol As New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "Customer Name"
TextCol.Width = 250
ts1.GridColumnStyles.Add(TextCol)
End Sub
To set up a desired format, add the following line before the
"ts1.GridColumnStyles.Add(TextCol)" line:

TextCol.Format = "t"

You can also use "T" for the long time pattern.

Hope this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <ss*********@ilogic.com> wrote in message
news:23*****************************@phx.gbl...
Ok. Can you give me some sample code on how to do this.
I'll attach some code I have so far so you can add the
rest to get the formatting code

GRID.TableStyles(rownum).GridColumnStyles("Date"). ..

Thank you,

Sebastian
-----Original Message-----
Sebastian,

You just haven't dug deep enough :-) The GridColumnStyles

collection is just
the right direction to pursue, and the next step would

get you just where
you want to be. See below.

FormatInfo is set on

System.Windows.Forms.DataGridColumnStyle class. This is
actually an abstract class, and has two implementations

by default -
DataGridTextBoxColumn and DataGridBoolColumn. As both of

these classes
inherit from DataGridColumnStyle, they obviosuly have

Format and FormatInfo
properties you can customize to achieve a desirable data

format.

And the GridColumnStyles collection contains just these
DataGridTextBoxColumns and DataGridBoolColumns.

Unfortunately, when the
columns are generated automatically, you cannot access

the column style
instances created behind the scenes. Therefore, you will

need to specify a
set of columns manually, and it is easily done with the

GridColumnStyles
collection designer.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <sS*********@ilogic.com> wrote in

message
news:1b*****************************@phx.gbl...
I don't know where your getting FormatInfo property from
but it doesn't exist for DataGridTableStyle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableStyle.GridColumnStyles
and it had no formating property.

Can someone advice how I get to this format property?

Thank you,

Seb
>-----Original Message-----
>Hi Sebastian,
>
>Initialize the FormatInfo property for the corresponding DataGridColumnStyle
>with a pre-created DateTimeFormatInfo instance. You can
probably achieve the
>same effect by playing just with the
DataGridColumnStyle.Format property (if
>an existing time-only format exists or can be specified
with a tailormade
>format string).
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Test Studio
>http://x-unity.miik.com.ua/teststudio.aspx
>Bring the power of unit testing to VS .NET IDE
>
>"Sebastian Santacroce" <sS*********@ilogic.com> wrote in message
>news:05****************************@phx.gbl...
>> How do I get a datetime field from a database to show
just
>> time in the datagrid. The default just shows date.
>>
>> Thank you
>>
>> Sebastian
>
>.
>


.


Nov 20 '05 #6
Sebastian,

When a grid is bound to a data source, two options are actually possible:

a) All grid column styles and a default table style are created
automatically behind the scenes. In this case, you CANNOT access the column
styles created automatically for you. I know - this is sad, but true.

b) You create the table style and populate the grid column styles manually.
You can do it either completely in code as it has been done in the example,
or use the appropriate collection designers as I have said searlier in this
thread.

Thus, I'm afraid you have nothing to modify unless you have already created
a bunch of data grid column styles for your actual data columns - but you
would know what to do then. So, the bottom line is that you should take the
example given and rework it to make it work with the data returned by the
stored procedure.

IMPORTANT: You should create table styles and grid column styles BEFORE
binding the grid to the data. This might actually be the problem you've
experienced.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <ss*********@ilogic.com> wrote in message
news:00****************************@phx.gbl...
Hey thanks for you help,
I think your on the right track but I'm getting the data
from a stored procedure in SQL Server and using a data
adapter and it already has a column with that name. So I
just want to modify that column not add a new one.If add
like it says below it tells me there already exists a
column mapping with that name.

What do I need to change to modify not add.

Thank you,

Sebastian
-----Original Message-----
GRID.TableStyles(rownum).GridColumnStyles("Date"). ..


Here's an example from the "DataGridTableStyle Class"

topic in MSDN:

Private Sub AddCustomDataTableStyle()
' Create a new DataGridTableStyle and set
' its MappingName to the TableName of a DataTable.
Dim ts1 As New DataGridTableStyle()
ts1.MappingName = "Customers"

' Add a GridColumnStyle and set its MappingName
' to the name of a DataColumn in the DataTable.
' Set the HeaderText and Width properties.

Dim boolCol As New DataGridBoolColumn()
boolCol.MappingName = "Current"
boolCol.HeaderText = "IsCurrent Customer"
boolCol.Width = 150
ts1.GridColumnStyles.Add(boolCol)

' Add a second column style.
Dim TextCol As New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "Customer Name"
TextCol.Width = 250
ts1.GridColumnStyles.Add(TextCol)
End Sub
To set up a desired format, add the following line before

the
"ts1.GridColumnStyles.Add(TextCol)" line:

TextCol.Format = "t"

You can also use "T" for the long time pattern.

Hope this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Sebastian Santacroce" <ss*********@ilogic.com> wrote in

message
news:23*****************************@phx.gbl...
Ok. Can you give me some sample code on how to do this.
I'll attach some code I have so far so you can add the
rest to get the formatting code

GRID.TableStyles(rownum).GridColumnStyles("Date"). ..

Thank you,

Sebastian
>-----Original Message-----
>Sebastian,
>
>You just haven't dug deep enough :-) The GridColumnStyles collection is just
>the right direction to pursue, and the next step would
get you just where
>you want to be. See below.
>
>FormatInfo is set on
System.Windows.Forms.DataGridColumnStyle class. This is
>actually an abstract class, and has two implementations
by default -
>DataGridTextBoxColumn and DataGridBoolColumn. As both of these classes
>inherit from DataGridColumnStyle, they obviosuly have
Format and FormatInfo
>properties you can customize to achieve a desirable data format.
>
>And the GridColumnStyles collection contains just these
>DataGridTextBoxColumns and DataGridBoolColumns.
Unfortunately, when the
>columns are generated automatically, you cannot access
the column style
>instances created behind the scenes. Therefore, you will need to specify a
>set of columns manually, and it is easily done with the
GridColumnStyles
>collection designer.
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Test Studio
>http://x-unity.miik.com.ua/teststudio.aspx
>Bring the power of unit testing to VS .NET IDE
>
>"Sebastian Santacroce" <sS*********@ilogic.com> wrote in message
>news:1b*****************************@phx.gbl...
>> I don't know where your getting FormatInfo property from >> but it doesn't exist for DataGridTableStyle object for >> VB .net 2002. I've attached it to my datagrid as a
>> TableStyles.
>>
>> The closest thing I could find in that was
>> DataGridTableStyle.GridColumnStyles
>> and it had no formating property.
>>
>> Can someone advice how I get to this format property?
>>
>> Thank you,
>>
>> Seb
>>
>>
>> >-----Original Message-----
>> >Hi Sebastian,
>> >
>> >Initialize the FormatInfo property for the
corresponding
>> DataGridColumnStyle
>> >with a pre-created DateTimeFormatInfo instance. You can >> probably achieve the
>> >same effect by playing just with the
>> DataGridColumnStyle.Format property (if
>> >an existing time-only format exists or can be specified >> with a tailormade
>> >format string).
>> >
>> >--
>> >Dmitriy Lapshin [C# / .NET MVP]
>> >X-Unity Test Studio
>> >http://x-unity.miik.com.ua/teststudio.aspx
>> >Bring the power of unit testing to VS .NET IDE
>> >
>> >"Sebastian Santacroce" <sS*********@ilogic.com> wrote in
>> message
>> >news:05****************************@phx.gbl...
>> >> How do I get a datetime field from a database to show >> just
>> >> time in the datagrid. The default just shows date.
>> >>
>> >> Thank you
>> >>
>> >> Sebastian
>> >
>> >.
>> >
>
>.
>


.


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Schu | last post by:
I am trying to show a grid in a text box in an aspx page but I am not able to convert the GUID to a string. Here is the line I am trying to get to work: textbox1.text =...
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
0
by: John | last post by:
Hi! Guys I think some of you can help me here. Here is the situation...... I have a following columns from different tables and get a Dataset to Bind with a data grid. 1)ItemId int...
4
by: Alan Silver | last post by:
hello, I have a database table that stores names of schools, and I want o write a page that allows someone to change the list. I was wondering about showing the schools in a table, with...
2
by: Andy Savelle | last post by:
I have recently started working with Visual Basic .NET. Having very little experiance in VB .NET, I am starting from the gound up with very simple programs. One of my first task to achieve is...
2
by: TerryW | last post by:
I am using a system.windows.forms.datagrid and i set it's data source to a system.data.datatable which has a column that's dataType is system.dateTime. When I try to enter minutes and seconds...
2
by: zafar | last post by:
in table i have a field for date and time, but in grid only date is shown, where i want to display the time only ( i am using ultra grid tool of infragestrics),, thanx if any body can help me for...
6
by: ajk | last post by:
Hi I was wondering how to show different properties in design and run-mode for a user control? Is it possible to do this when implementing the System.ComponentModel.ICustomTypeDescriptor...
1
by: =?iso-8859-1?B?R2VhcvNpZA==?= | last post by:
Strange problem... Have a gridview on a page (within an update panel) for displaying event dates. GridView loads fine first time around with the PageLoad. There are 2 text fields a user can...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.