DataGridView column format

  • Thread starter Pitaridis Aristotelis
  • Start date
P

Pitaridis Aristotelis

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.
 
G

gene kelley

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.DataGridViewCellFormattingEventArgs) _
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top