Vb.net Datagridview Mükerrerleri Teke Düşürme.

01/05/2017, 19:29

feraz

Ekteki dosyadaki Datagriddeki veriler nasıl benzersiz yapılır?

Kaydetmeye felan gerek yok sadece Datagridde tek olarak görükecek.
Örnek 5 tane a varsa bir tane a olacak.
İnternetten kod buldum çalışmıyor.

Saygılar.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       For i As Integer = 0 To Me.DataGridView1.RowCount - 2

           For j As Integer = i + 1 To Me.DataGridView1.RowCount - 2
               If DataGridView1.Rows(i).Cells(0).Value = DataGridView1.Rows(j).Cells(0).Value Then
                   DataGridView1.Rows.Remove(DataGridView1.Rows(i))

               End If
           Next
       Next
   End Sub
01/05/2017, 22:03

alican60

Kod:
Buton 1 kodlarını bunlarla değiştiriniz.

      Dim satır = DataGridView1.Rows.Count - 1
       Dim x As Integer = 0
       While x < satır - 2
           For y As Integer = (satır - 2) To (x + 1) Step -1
               If DataGridView1.Rows(x).Cells(0).Value.ToString() = DataGridView1.Rows(y).Cells(0).Value.ToString() Then
                   DataGridView1.Rows.Remove(DataGridView1.Rows(y))
                   satır -= 1
               End If
           Next
           x += 1
       End While
02/05/2017, 05:24

feraz

Malisef hocam.

Kod çalışınca dosyadaki cc 2 adet çıktı.

Teşekkürler.
02/05/2017, 19:17

alican60

Kod:
      Dim satır = DataGridView1.Rows.Count - 1
       Dim x As Integer = 0
       While x < satır - 1
           For y As Integer = (satır - 1) To (x + 1) Step -1
               If DataGridView1.Rows(x).Cells(0).Value.ToString() = DataGridView1.Rows(y).Cells(0).Value.ToString() Then
                   DataGridView1.Rows.Remove(DataGridView1.Rows(y))
                   satır -= 1
               End If
           Next
           x += 1
       End While
02/05/2017, 22:40

feraz

Ali hocam diğer tarfta yazdığım burdada geçerli.


Teşekkürler.
Galiba sizden başka vb.net anlayan yok burda
03/05/2017, 20:45

feraz

Ali Can hocam alttaki kodla sorunu hallettim.
Verdiğiniz kodun
 başına
Kod:
Me.DataGridView1.AllowUserToAddRows = True
sonunada
Kod:
Me.DataGridView1.AllowUserToAddRows = False
ekledim.

Teşekkürler yadım için.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Me.DataGridView1.AllowUserToAddRows = True 'Satir ekleme olayini iptal eder ayarlardaki
       Dim satır = DataGridView1.Rows.Count - 1
       Dim x As Integer = 0
       While x < satır - 1
           For y As Integer = (satır - 1) To (x + 1) Step -1
               If DataGridView1.Rows(x).Cells(0).Value.ToString() = DataGridView1.Rows(y).Cells(0).Value.ToString() Then
                   DataGridView1.Rows.Remove(DataGridView1.Rows(y))
                   satır -= 1
               End If
           Next
           x += 1
       End While
       Me.DataGridView1.AllowUserToAddRows = False
   End Sub