This is a migrated thread and some comments may be shown as answers.

Formatting GridView Columns for WinForms

4 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hector
Top achievements
Rank 1
Hector asked on 16 May 2015, 04:17 AM

Hello people

I want to remove the hour of my date column.

 

I just have proved these three sentences but It don't work

'dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0:dddd, MMM dd, yyyy}"
'dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0:yyyy/MM/dd}"
'dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0:dd - MM - yyyy}"

My Form
Private Sub Form5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
 Dim tabla3 As New DataTable()

'cancelación y devolución
        tabla3.Columns.Add("Código del pedido")
        tabla3.Columns.Add("Estado del pedido")
        tabla3.Columns.Add("Fecha de Cancelación o Devolución")
        tabla3.Columns.Add("Hora de cancelación")
        tabla3.Columns.Add("Forma de pago")

        dgvCanDev.DataSource = tabla3
        '===========================================================
        'Modificando el ancho de las columnas
        dgvCanDev.Columns("Código del pedido").Width = 140
        dgvCanDev.Columns("Estado del pedido").Width = 153
        dgvCanDev.Columns("Fecha de Cancelación o Devolución").Width = 210
        dgvCanDev.Columns("Hora de cancelación").Width = 150
        dgvCanDev.Columns("Forma de pago").Width = 150

'Assing formatting
dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0:dddd, MMM dd, yyyy}"
        'dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0:yyyy/MM/dd}"
        'dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0:dd - MM - yyyy}"

End Sub

Also I try

Private Sub dgvCanDev_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles dgvCanDev.CellFormatting
        e.CellElement.TextAlignment = ContentAlignment.MiddleCenter

    End Sub

I let an image

4 Answers, 1 is accepted

Sort by
0
Hector
Top achievements
Rank 1
answered on 16 May 2015, 09:39 AM
  Hello

The solution is

tabla3.Columns("Fecha de Cancelación o Devolución").DataType = GetType(Date) 'Convierte la columna a tipo fecha

dgvCanDev.Columns("Fecha de Cancelación o Devolución").FormatString = "{0: dddd, dd, MMM, yyyy}"

But I have another error with the date format

tabla2.Columns.Add("Hora del pedido").DataType = GetType(TimeSpan)

dgvPedidos.Columns("Hora del pedido").FormatString = "{0:hh:mm:ss}"

It gives me the following error in the images

0
Hector
Top achievements
Rank 1
answered on 16 May 2015, 09:40 AM
Images
0
Accepted
Dimitar
Telerik team
answered on 18 May 2015, 03:23 PM
Hello Hector,

Thank you for writing.

In this case you should escape the colon, detailed information is available here: Custom TimeSpan Format Strings.

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Hector
Top achievements
Rank 1
Answers by
Hector
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or