I have a datagridvied with several columns and one with date and the format is

Me.DataGridView1.Columns("Doopdatum").DefaultCellStyle.Format = "yyyy - MM - dd dddd"


Me.DataGridView1.Columns("Doopdatum").DefaultCellStyle.Format = "dddd dd - MM - yyyy"

Depends on the button i press

My problem is when i reverse from "yyyy - MM - dd dddd" to "dddd dd - MM - yyyy" It dos not work proper

I have the folowing code to reverse the date

Private Sub DoopdatumOmdraaienToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DoopdatumOmdraaienToolStripMenuItem.Click
        If DoopdatumOmdraaienToolStripMenuItem.CheckState = CheckState.Checked Then
            Me.DataGridView1.Columns("Doopdatum").DefaultCellStyle.Format = "dddd  dd - MM - yyyy"
            For Each row As DataGridViewRow In DataGridView1.Rows
                Dim date1 As Date = row.Cells(5).Value
                row.Cells(5).Value = Format(date1.ToString("dddd  dd - MM - yyyy"))

            With My.Settings
                .Setting25 = True
            End With
        End If

        If DoopdatumOmdraaienToolStripMenuItem.CheckState = CheckState.Unchecked Then
            Me.DataGridView1.Columns("Doopdatum").DefaultCellStyle.Format = "yyyy - MM - dd  dddd"
            For Each row As DataGridViewRow In DataGridView1.Rows
                Dim date1 As Date = row.Cells(5).Value
                row.Cells(5).Value = Format(date1.ToString("yyyy - MM - dd  dddd"))
            With My.Settings
                .Setting25 = False
            End With

        End If
    End Sub

My outut gives the following when it is in dddd dd MM yyyy.
1111 - 01 - 31 Dinsdag
1111 - 01 - 04 Zaterdag
Donderdag 05 - 01 - 1111

and so on

What am i doing wrong
I tried everything Please help

10 Months
Discussion Span
Last Post by r310070

I see what happens but i do not know why.
When i order the date column in the datagridview to asc or desc the Id column is
Not in order then it is like 4 3 7 1 2 6 5 or what else Or what else. Depence on the date.
When i reverse the date of each row than it is not working proper.
Wen i orde the id column to asc or desc so that the id column is 1 2 3 4 5 6 7
The i can reverse the date column proper


I have created a attechment you can download it at

its created with VS 2015 Net framework 4.6.1 dutch version
Database is SQLITE

Reorder the dates and reverse it Code is all included

Edited by johnnyd1963


Yes jjjj dos not work. Gives an error
The conversion of string Tuesday 03 - 01 - jjjj to Type Date is invalid.


The problem is that you enter a string into a cell formatted for a date.
Just change
row.Cells(5).Value = Format(date1.ToString("yyyy - MM - dd dddd"))
row.Cells(5).Value = date1
that should work.
Me.DataGridView1.Columns("Doopdatum").DefaultCellStyle.Format = "yyyy - MM - dd dddd"
defines the display of the value, but the value is always a date.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.