VB.NET How to Remove Duplicate Values in DataGridView / DataTable

VB.NET tutorial for beginner - How to remove duplicate row from datagridview or datatable in Vb.Net? Hello guys, today i'll show you how to make simple applications and work with DataGridView in vb.net. so we will remove a value / data in a datagridview if they are same. we will delete this row If the row in datagridview have a value and same with any value from any row. lets do it.

Read : How to Insert data Into DataGridView from MySql Database?

Cara menghapus Duplicate Row DataGridView VB.NET

Langsung saja, buatlah sebuah project baru dengan nama "RemoveDuplicate" dan pada Form1.vb silahkan design seperti tampilan dibawah ini :

Pada button1 tuliskan seluruh source code berikut :

Source Code Remove Duplicate Rows

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

' you can add data into DataGridView using DataTable with you Database (MySQL, Sql Server, Ms Access.)
' Tutorials Available in Description or see my offical website "www.hc-kr.com"
' just dollow step by step

Dim Data As String() ' declaration data while insert into datagrid
Data = {TextBox1.Text, TextBox2.Text, TextBox3.Text}
DataGridView1.Rows.Add(Data) ' add data into DataGridView

' do loop trough rows in datagrid from the top
For a As Integer = 0 To DataGridView1.Rows.Count - 1
For b As Integer = a + 1 To DataGridView1.Rows.Count - 1
' check trough rows in datagrid if have same value
If DataGridView1.Rows(a).Cells(0).Value = DataGridView1.Rows(b).Cells(0).Value Then

' if same, just give a message
MsgBox("Value same, its will delete" & DataGridView1.Rows(a).Cells(0).Value)

' then, remove the row
DataGridView1.Rows.Remove(DataGridView1.Rows(a))
a -= 1
End If
Next
Next
End Sub
Setelah selesai, langsung saja di run "F5".

Penjelasan :
Jika kita memberikan input yang sama pada cells(0) datagridview atau dengan id ("Nama") atau dengan kata lain jika memiliki nama lebih dari satu  maka akan ada peringatan sebelum menghapus row paling bawah dari row yang sama. dengan menggunakan perintah Rows.Remove().

Jika masih bingung dengan penjelasan diatas, silahkan lihat video tutorial berikut :

Video Tuotrial How To Remove Duplicate Value DataGridView


Download Source Code Aplikasi Remove Duplicate