473,683 Members | 2,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2965
Hi Sebastian,

Initialize the FormatInfo property for the corresponding DataGridColumnS tyle
with a pre-created DateTimeFormatI nfo instance. You can probably achieve the
same effect by playing just with the DataGridColumnS tyle.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*********@il ogic.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 DataGridTableSt yle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableSt yle.GridColumnS tyles
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 DataGridColumnS tylewith a pre-created DateTimeFormatI nfo instance. You can probably achieve thesame effect by playing just with the DataGridColumnS tyle.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*********@il ogic.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 GridColumnStyle s 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.DataGridC olumnStyle class. This is
actually an abstract class, and has two implementations by default -
DataGridTextBox Column and DataGridBoolCol umn. As both of these classes
inherit from DataGridColumnS tyle, they obviosuly have Format and FormatInfo
properties you can customize to achieve a desirable data format.

And the GridColumnStyle s collection contains just these
DataGridTextBox Columns and DataGridBoolCol umns. 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 GridColumnStyle s
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*********@il ogic.com> wrote in message
news:1b******** *************** ******@phx.gbl. ..
I don't know where your getting FormatInfo property from
but it doesn't exist for DataGridTableSt yle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableSt yle.GridColumnS tyles
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

DataGridColumnS tyle
with a pre-created DateTimeFormatI nfo instance. You can

probably achieve the
same effect by playing just with the

DataGridColumnS tyle.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*********@il ogic.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.TableStyle s(rownum).GridC olumnStyles("Da te")...

Thank you,

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

You just haven't dug deep enough :-) The GridColumnStyle s 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.DataGridC olumnStyle class. This isactually an abstract class, and has two implementations by default -DataGridTextBo xColumn and DataGridBoolCol umn. As both of these classesinherit from DataGridColumnS tyle, they obviosuly have Format and FormatInfoproperties you can customize to achieve a desirable data format.
And the GridColumnStyle s collection contains just these
DataGridTextBo xColumns and DataGridBoolCol umns. 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 GridColumnStyle scollection 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*********@il ogic.com> wrote in messagenews:1b******* *************** *******@phx.gbl ...
I don't know where your getting FormatInfo property from
but it doesn't exist for DataGridTableSt yle object for
VB .net 2002. I've attached it to my datagrid as a
TableStyles.

The closest thing I could find in that was
DataGridTableSt yle.GridColumnS tyles
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 DataGridColumnS tyle
>with a pre-created DateTimeFormatI nfo instance. You can

probably achieve the
>same effect by playing just with the

DataGridColumnS tyle.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*********@il ogic.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.TableStyle s(rownum).GridC olumnStyles("Da te")...

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

Private Sub AddCustomDataTa bleStyle()
' Create a new DataGridTableSt yle and set
' its MappingName to the TableName of a DataTable.
Dim ts1 As New DataGridTableSt yle()
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 DataGridBoolCol umn()
boolCol.Mapping Name = "Current"
boolCol.HeaderT ext = "IsCurrent Customer"
boolCol.Width = 150
ts1.GridColumnS tyles.Add(boolC ol)

' Add a second column style.
Dim TextCol As New DataGridTextBox Column()
TextCol.Mapping Name = "custName"
TextCol.HeaderT ext = "Customer Name"
TextCol.Width = 250
ts1.GridColumnS tyles.Add(TextC ol)
End Sub
To set up a desired format, add the following line before the
"ts1.GridColumn Styles.Add(Text Col)" 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*********@il ogic.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.TableStyle s(rownum).GridC olumnStyles("Da te")...

Thank you,

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

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

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.DataGridC olumnStyle class. This is
actually an abstract class, and has two implementations

by default -
DataGridTextBo xColumn and DataGridBoolCol umn. As both of

these classes
inherit from DataGridColumnS tyle, they obviosuly have

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

format.

And the GridColumnStyle s collection contains just these
DataGridTextBo xColumns and DataGridBoolCol umns.

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

GridColumnStyle s
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*********@il ogic.com> wrote in

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

The closest thing I could find in that was
DataGridTableSt yle.GridColumnS tyles
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 DataGridColumnS tyle
>with a pre-created DateTimeFormatI nfo instance. You can
probably achieve the
>same effect by playing just with the
DataGridColumnS tyle.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*********@il ogic.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*********@il ogic.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.TableStyle s(rownum).GridC olumnStyles("Da te")...


Here's an example from the "DataGridTableS tyle Class"

topic in MSDN:

Private Sub AddCustomDataTa bleStyle()
' Create a new DataGridTableSt yle and set
' its MappingName to the TableName of a DataTable.
Dim ts1 As New DataGridTableSt yle()
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 DataGridBoolCol umn()
boolCol.Mapping Name = "Current"
boolCol.HeaderT ext = "IsCurrent Customer"
boolCol.Width = 150
ts1.GridColumnS tyles.Add(boolC ol)

' Add a second column style.
Dim TextCol As New DataGridTextBox Column()
TextCol.Mapping Name = "custName"
TextCol.HeaderT ext = "Customer Name"
TextCol.Width = 250
ts1.GridColumnS tyles.Add(TextC ol)
End Sub
To set up a desired format, add the following line before

the
"ts1.GridColum nStyles.Add(Tex tCol)" line:

TextCol.Form at = "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*********@il ogic.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.TableStyle s(rownum).GridC olumnStyles("Da te")...

Thank you,

Sebastian
>-----Original Message-----
>Sebastian,
>
>You just haven't dug deep enough :-) The GridColumnStyle s 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.DataGridC olumnStyle class. This is
>actually an abstract class, and has two implementations
by default -
>DataGridTextBo xColumn and DataGridBoolCol umn. As both of these classes
>inherit from DataGridColumnS tyle, they obviosuly have
Format and FormatInfo
>properties you can customize to achieve a desirable data format.
>
>And the GridColumnStyle s collection contains just these
>DataGridTextBo xColumns and DataGridBoolCol umns.
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
GridColumnStyle s
>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*********@il ogic.com> wrote in message
>news:1b******* *************** *******@phx.gbl ...
>> I don't know where your getting FormatInfo property from >> but it doesn't exist for DataGridTableSt yle object for >> VB .net 2002. I've attached it to my datagrid as a
>> TableStyles.
>>
>> The closest thing I could find in that was
>> DataGridTableSt yle.GridColumnS tyles
>> 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
>> DataGridColumnS tyle
>> >with a pre-created DateTimeFormatI nfo instance. You can >> probably achieve the
>> >same effect by playing just with the
>> DataGridColumnS tyle.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*********@il ogic.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
2302
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 = grid.datakeys(e.item.itemindex) Can anyone tell me how to do this? Schu
1
840
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 controlling the visibility of columns in the DataGrid control. The problem usually comes down to one fact. The DataGrid has a property called AutoGenerateColumns. The default value is "True". This means that when AutoGenerateColumns is set to True,...
0
1012
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 2)FeatureId smallint 3)ItemName nvarchar(255)
4
1221
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 existing school names being in textboxes, each with a "delete" checkbox. Modifying a school name would involve typing the changes in the textbox and clicking a Submit button. Deleting a school would involve checking the school(s) to be deleted, and...
2
2468
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 accessing an AS/400 data file ( in real time located on the AS400) and displaying it on a webpage over the internet. I am wanting to acheive this by placing the data in a data grid on the web page. I have been working with entry level (tutorials)...
2
1952
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 into the grid it removes that time data and leaves only the date. The time information is still there though. How can I make the time visible? TIA TerryW
2
3969
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 this
6
2771
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 interface? e.g. when selecting the control from a toolbox with controls other properties show up when the program is in design mode than in run mode.
1
3114
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 use to enter a new new. Upon clicking the "Add Button" these are added to the database, the gridview refreshes its datasource and the GridView is reloaded through
0
8568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8504
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9042
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8922
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8751
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6429
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5789
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2195
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.