Getting time format in datagrid

  • Thread starter Sebastian Santacroce
  • Start date
S

Sebastian Santacroce

I'm trying to format datetime column in datagrid to a time
format rather than date. I'm using code:

Dim myGridTextBoxColumn As DataGridTextBoxColumn = New
DataGridTextBoxColumn()

myGridTextBoxColumn = CType(datagrid.TableStyles
(0).GridColumnStyles("StartDate"), DataGridTextBoxColumn)

myGridTextBoxColumn.Format="hh:mm:ss tt"

However, that last line always give error"Object reference
not set to an instance of an object."

What am I doing wrong?

Thank you

Sebastian
 
K

Ken Tucker

Hi,

Dim cm As CurrencyManager = CType(Me.BindingContext(dvClient),
CurrencyManager)

Dim pd As PropertyDescriptor = cm.GetItemProperties()("AppointDate")

Dim colDate As New DataGridTextBoxColumn(pd, "t")

With colDate

..MappingName = "ApointDate"

..HeaderText = "Date"

..Width = 100

End With

Ken
 
S

sebastian Santacroce

I tryed to apply this to what I have but it did not do
anything. Heres the code I used in reference to my first
email trying to merge with your code.
'ds is the dataSet
'StartTime is the field column name I want as time not
date.

Please clarify were I went wrong.

Thank you.
Dim cm As CurrencyManager = CType(Me.BindingContext(ds),
CurrencyManager)

Dim pd As System.ComponentModel.PropertyDescriptor
= cm.GetItemProperties()("StartTime")

Dim colDate As New DataGridTextBoxColumn(pd, "t")

With colDate

.MappingName = "StartTime"

.HeaderText = "StartTime"

.Width = 100

End With
 

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