Jump to content

Ordenar data datagridvew


sabing
Go to solution Solved by sabing,

Recommended Posts

Eu estou com dificuldade de ordenar data no datagridview, poderia me ajudar

 

For Each PrimeiraLinha As DataGridViewRow In Me.TabelaVisualizar.Rows
                If PrimeiraLinha.Index >= 0 Then
                    'For Each SegundaLinha As DataGridViewRow In Me.TabelaVisualizar.Rows
                    Dim dt1 As DateTime = Convert.ToDateTime(Me.TabelaVisualizar.Rows(PrimeiraLinha.Index - 1).Cells(5).Value)
                    Dim dt2 As DateTime = Convert.ToDateTime(Me.TabelaVisualizar.Rows(PrimeiraLinha.Index).Cells(5).Value)
                    If dt2 < dt1 Then
                        Me.TabelaVisualizar.Rows.RemoveAt(PrimeiraLinha.Index)
                        Me.TabelaVisualizar.Rows.Insert(PrimeiraLinha.Index + 1, PrimeiraLinha)
                        Me.TabelaVisualizar.ClearSelection()
                    End If
                    'Next
                End If

 

Quero ordenar a data em ordem crescente

Link to comment
Share on other sites

For Each PrimeiraLinha As DataGridViewRow In Me.TabelaVisualizar.Rows
    If PrimeiraLinha.Index > 1 Then            
       Dim dt1 As DateTime = Convert.ToDateTime(Me.TabelaVisualizar.Rows(PrimeiraLinha.Index -1).Cells(5).Value.toString())
       Dim dt2 As DateTime = Convert.ToDateTime(Me.TabelaVisualizar.Rows(PrimeiraLinha.Index).Cells(5).Value.toString())
       If dt2 < dt1 Then
          Me.TabelaVisualizar.Rows.RemoveAt(PrimeiraLinha.Index)
          Me.TabelaVisualizar.Rows.Insert(PrimeiraLinha.Index + 1, PrimeiraLinha)
          Me.TabelaVisualizar.ClearSelection()
       End If               
    End If
Next

Também não funciona, pela minha lógica era para estar funcionando?!??

Link to comment
Share on other sites

  • Solution

Resolvido

 

 For Each Linha As DataGridViewRow In Me.TabelaVisualizar.Rows
                If Linha.Index >= 1 Then
                    Dim dt1 As DateTime = Convert.ToDateTime(Me.TabelaVisualizar.Rows(Linha.Index - 1).Cells(5).Value)
                    Dim dt2 As DateTime = Convert.ToDateTime(Me.TabelaVisualizar.Rows(Linha.Index).Cells(5).Value)
                    If dt2.Date < dt1.Date Then
                        Me.TabelaVisualizar.Rows.RemoveAt(Linha.Index)
                        Me.TabelaVisualizar.Rows.Insert(Linha.Index + 1, Linha)
                        Me.TabelaVisualizar.ClearSelection()
                    End If
                End If
            Next

Funcionou!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.