sabing Posted July 13, 2022 at 06:33 PM Report Share #626441 Posted July 13, 2022 at 06:33 PM Boa tarde, eu estou com dificuldade de fazer uma lógica de remover dados repetidos em um datagridview , exemplo na tabela tem 4 valores e tenho 1 valor repetidos eu preciso indetificar um valore repetido e remover esse valor eu fiz um lógica , mais não funciona corretamente pode me ajudar Sub Limpar_dados_repetidos() If TabelaFazenda.Rows.Count() > 1 Then For j As Integer = TabelaFazenda.Rows.Count() - 1 To 0 Step -1 Dim s As Boolean = False For x As Integer = 0 To TabelaFazenda.Rows.Count() - 1 If TabelaFazenda.Rows(x).Cells(0).Value = TabelaFazenda.Rows(j).Cells(0).Value Then If s = False Then TabelaFazenda.Rows(x).DefaultCellStyle.BackColor = Color.Red s = True End If End If Next Next For j As Integer = TabelaFazenda.Rows.Count() - 1 To 0 Step -1 If TabelaFazenda.Rows(j).DefaultCellStyle.BackColor = Color.Red Then Me.TabelaFazenda.Rows.RemoveAt(j) End If Next End If End Sub Link to comment Share on other sites More sharing options...
sabing Posted July 13, 2022 at 09:09 PM Author Report Share #626442 Posted July 13, 2022 at 09:09 PM Eu fiz esse outro metodo , parece que funcionou If TabelaFazenda.Rows.Count() > 1 Then Dim s As Boolean = False For i As Integer = 0 To TabelaFazenda.Rows.Count() - 1 For j As Integer = 0 To TabelaFazenda.Rows.Count() - 1 If Not (i = j) Then If s = False Then If TabelaFazenda.Rows(j).Cells(0).Value = TabelaFazenda.Rows(i).Cells(0).Value Then TabelaFazenda.Rows(i).DefaultCellStyle.BackColor = Color.Red s = True Else s = False End If End If End If Next Next For j As Integer = TabelaFazenda.Rows.Count() - 1 To 0 Step -1 If TabelaFazenda.Rows(j).DefaultCellStyle.BackColor = Color.Red Then Me.TabelaFazenda.Rows.RemoveAt(j) End If Next End If Link to comment Share on other sites More sharing options...
sabing Posted July 13, 2022 at 11:35 PM Author Report Share #626443 Posted July 13, 2022 at 11:35 PM Não funcionou! codigo Olha o link da imagem https://ibb.co/D418pWy 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