Format a date column in a datagrid

Hi

I have a column in my datagrid which is a date field. It is represented in the grid as 'mm/dd/yy' - but in Australia we prefer 'dd/mm/yy'

The grids datasource is set to a dataset at runtime.

I format the grid at runtime using tableStyles.
e.g.

    Dim activityDate As New DataGridTextBoxColumn
    activityDate.MappingName = "activityDate"
    activityDate.HeaderText = "Date"
    activityDate.Width = 40
    ts.GridColumnStyles.Add(activityDate)

    Dim description As New DataGridTextBoxColumn
    description.MappingName = "description"
    description.HeaderText = "Details"
    description.Width = 200
    ts.GridColumnStyles.Add(description)

    grid.TableStyles.Add(ts)


Thanks
Bruce



Answer this question

Format a date column in a datagrid

  • bswaters

    not sure if sqlce supports it but it works in normal sql server

    try adding this in the SELECT statement:
    CONVERT(nvarchar(10), DateReceived, 103) As [Date Received]

    eg SELECT CONVERT(nvarchar(10), DateReceived, 103) As [Date Received] FROM tbl_dates


  • leabre

    Too bad, data grid formatting is not available on NETCF, but in this case you probably can achieve desired result by tweaking device's locale settings. After that all dates would be in this format.

    Alternative is rather unpleasant and includes creating extra text column and populating it with formatted strings.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />



  • Format a date column in a datagrid