0

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"

or

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"))
            Next

            With My.Settings
                .Setting25 = True
                My.Settings.Save()
            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"))
            Next
            With My.Settings
                .Setting25 = False
                My.Settings.Save()
            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

3
Contributors
5
Replies
54
Views
1 Month
Discussion Span
Last Post by r310070
0

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

0

I have created a attechment you can download it at
www.dohmen-stamboom.nl/downloads/DATE_REVERSE.zip

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

0

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

0

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"))
into
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.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.