sabing Posted February 18, 2022 at 01:04 AM Report Share #625428 Posted February 18, 2022 at 01:04 AM 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 More sharing options...
sabing Posted February 18, 2022 at 03:13 PM Author Report Share #625435 Posted February 18, 2022 at 03:13 PM 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 More sharing options...
Solution sabing Posted February 18, 2022 at 11:26 PM Author Solution Report Share #625436 Posted February 18, 2022 at 11:26 PM 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now