Datum van DataGridView converteren

Status
Niet open voor verdere reacties.

Jan92

Gebruiker
Lid geworden
17 feb 2010
Berichten
111
Hallo, programmeurs

Ik heb op mijn Form 2 DGV staan met elk slechts 2 kolommen.

In de 1ste DGV staat data (kolom 1 = datums, kolom 2 = tekst)

De 2de DGV is leeg

Nu wil ik de gegevens van DGV 1 overzetten naar DGV 2 maar met de datums in een andere opmaak...


Code:
                For Each Row As DataGridViewRow In Me.DataGridView1.Rows

                Dim intcount As Integer = 0

                REM Opmaak VerlofDatum = "ddd.   dd-MM-yyyy"

                Dim VerlofDatum As String = Me.DataGridView2.Rows(intcount).Cells(0).Value

                Dim VerlofTekst As String = Me.DataGridView2.Rows(intcount).Cells(1).Value

                REM De datum opmaak wijzigen :

                Dim DatumAnders As String = Format(VerlofDatum, "dd-MM-yyyy   ddd.")

                Dim n As Integer = DataGridView2.Rows.Add()

                DataGridView2.Rows(n).Cells(0).Value = DatumAnders

                DataGridView2.Rows(n).Cells(1).Value = VerlofTekst
                
                intcount += 1

                Next

Wat doe ik hier fout ? :confused:
 
Oeps !

Regel 4 en 5 moet natuurlijk DGV 1 zijn ! (maar dat is de fout niet)

Hier dus nogmaals de code:

Code:
                For Each Row As DataGridViewRow In Me.DataGridView1.Rows
                Dim intcount As Integer = 0
                'Opmaak VerlofDatum = "ddd.   dd-MM-yyyy"
                Dim VerlofDatum As String = Me.DataGridView1.Rows(intcount).Cells(0).Value
                Dim VerlofTekst As String = Me.DataGridView1.Rows(intcount).Cells(1).Value
                'De datum opmaak wijzigen
                Dim DatumAnders As String = Format(VerlofDatum, "dd-MM-yyyy   ddd.")

                Dim n As Integer = DataGridView2.Rows.Add()
                DataGridView2.Rows(n).Cells(0).Value = DatumAnders
                DataGridView2.Rows(n).Cells(1).Value = VerlofTekst
                '
                intcount += 1
                Next
 
Dit zou moeten werken:

[cpp]Dim dat As New Date
Date.TryParse(VerlofDatum, dat)
Dim DatumAnders As String = Format(dat, "dd-MM-yyyy ddd.")[/cpp]

Format werkt in dit geval alleen met Date-objecten.
 
Hartelijk dank, JoZ1

Dat is wat ik zocht. :thumb:

Voor wie het ook zou kunnen gebruiken, hierbij de oplossing:

Code:
           Dim intcount As Integer = 0

           For Each Row As DataGridViewRow In Me.DataGridView1.Rows

                REM Opmaak VerlofDatum = "ddd.   dd-MM-yyyy"

                Dim FDdatum As String = Me.DataGridView1.Rows(intcount).Cells(0).Value

                Dim FDnaam As String = Me.DataGridView1.Rows(intcount).Cells(1).Value

                REM De datum opmaak wijzigen

                Dim dat As New Date

                Date.TryParse(FDdatum, dat)

                Dim DatumAnders As String = Format(dat, "dd-MM-yyyy   ddd.")

                REM Overzetten naar DGV 2

                DataGridView2.Rows.Add(DatumAnders, FDnaam)

                intcount += 1

           Next
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan