473,325 Members | 2,671 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,325 software developers and data experts.

DataGridView column format

I have a DataGridView which displays some data from a database. One of the
columns contains the time of a event. The problem is that except the time,
it displays the date as well. An example of what I see in every row of the
column is:

30/12/1899 8:45 pm

How can I format the column so that it will display only the time.
Oct 2 '06 #1
2 15584
On Mon, 2 Oct 2006 09:24:37 +0300, "Pitaridis Aristotelis" <pi*******@hotmail.com>
wrote:
>I have a DataGridView which displays some data from a database. One of the
columns contains the time of a event. The problem is that except the time,
it displays the date as well. An example of what I see in every row of the
column is:

30/12/1899 8:45 pm

How can I format the column so that it will display only the time.
For a column named colDate containing a date/time value, format to short time:

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) _
Handles DataGridView1.CellFormatting
If Me.DataGridView1.Columns(e.ColumnIndex).Name = "colDate" Then
e.Value = String.Format("{0:t}", e.Value)
End If

End Sub

Gene
Oct 2 '06 #2
Thank you very much Gene.

It works fine

Aristotelis

? "gene kelley" <ok**@by.me?????? ??? ??????
news:o0********************************@4ax.com...
>
On Mon, 2 Oct 2006 09:24:37 +0300, "Pitaridis Aristotelis"
<pi*******@hotmail.com>
wrote:
>>I have a DataGridView which displays some data from a database. One of the
columns contains the time of a event. The problem is that except the time,
it displays the date as well. An example of what I see in every row of the
column is:

30/12/1899 8:45 pm

How can I format the column so that it will display only the time.

For a column named colDate containing a date/time value, format to short
time:

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As
System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) _
Handles DataGridView1.CellFormatting
If Me.DataGridView1.Columns(e.ColumnIndex).Name = "colDate" Then
e.Value = String.Format("{0:t}", e.Value)
End If

End Sub

Gene

Oct 3 '06 #3

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

Similar topics

1
by: thomasp | last post by:
I have a datagridview in vb.net 2005 that pulls its data from an Access Database. The database has a time column. When you view the data in Access it shows only a time in 24hour format. When the...
10
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column...
5
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
5
by: TheSteph | last post by:
Hi ! I have a DataGridView with a Date (DateTime) Column. When a user edit the cell and change the date I woulk like to allow him to write "081501" and programmatically transform the entered...
3
by: Cdude | last post by:
I am using this code at the moment to format the column this.itemsDataGrid.Columns.DefaultCellStyle.Format = "c"; but i get the error "Object reference not set to an instance of an object. "...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
0
by: modolamara | last post by:
Hi people, im importing a date column from a mysql database to a datagridview but it automatically changes the date format from 'YYYY-MM-DD' (Mysql format) to 'MM/DD/YYYY' since the user has...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.