Click here to Skip to main content
12,997,038 members (129,087 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, im having data populate in:
EG1001 S1
EG1001 S2
EG1001 S3

i want it achieve:
EG1001 s1
-blank- s2
-blank- s3

EG1002 S2
-blank- S4

populated in datagridview.

tried with this code:
Dim i As Integer

For i = 0 To dgvModStud.Rows.Count - 1
If dgvModStud.Rows(i).Cells(0).Value = True Then
dgvModStud.Rows(i).Cells(0).Value = String.Empty
Continue For

End If

but it doesnt work, why is it so?

thanks in advance!
Posted 7-Jul-13 16:59pm
If you don't want duplicates, why did you allow them in first place? As to your code, why would you think it remove duplicates? You never compare any values...
12345_abcde 8-Jul-13 0:00am
i wanted a blank value to the outcome i stated above.
i dont really know how to compare values.
12345_abcde 8-Jul-13 0:03am
how about this code?

Dim i As Integer
For Each row As DataGridViewRow In dgvModStud.Rows
Dim obj(row.Cells.Count - 1) As Object
For i = 0 To row.Cells.Count - 1
If obj(i) = row.Cells(i).Value Then
row.Cells(i).Value = String.Empty
Continue For
End If


it's not working though ><
Kuthuparakkal 8-Jul-13 0:52am
Review my solution posted...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this:
Dim table As New DataTable
' Create four typed columns in the DataTable.
table.Columns.Add("MyKey", GetType(String))
table.Columns.Add("MyValue", GetType(String))
table.Rows.Add("EG1001", "S1")
table.Rows.Add("EG1001", "S2")
table.Rows.Add("EG1001", "S3")
table.Rows.Add("EG2001", "S4")
table.Rows.Add("EG2001", "S5")
table.Rows.Add("EG2001", "S6")
Dim strKey As String
Dim DistinctCol As String()
Dim dtDistinct As New DataTable
DistinctCol = New String() {"MyKey"}
Dim i As Integer
dtDistinct = table.DefaultView.ToTable(True, DistinctCol)
Dim foundRows() As DataRow
For Each row As DataRow In dtDistinct.Rows
    strKey = row(0).ToString()
    foundRows = table.Select("MyKey = '" & strKey & "'")
    If (foundRows.Length > 1) Then
        For i = 1 To foundRows.GetUpperBound(0)
            foundRows(i)("MyKey") = "" ' OR "-blank-" whatever you like
        Next i
    End If
Next row
'Now you can use the datatable "table" as your source for gridview.


12345_abcde 8-Jul-13 3:44am
i thanks for your answer, but i cant list out all the data i want.
right now i have:
Dim j, i As Integer
j = 0
For i = 1 To dgvModStud.Rows.Count - 1

If dgvModStud.Rows(i).Cells(0).Value = dgvModStud.Rows(j).Cells(0).Value Then

dgvModStud.Rows(i).Cells(0).Value = String.Empty

End If

Next i

but only one modulecode is applied. the others are not.
any idea how should i go about getting it applied to other modulecodes as well?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100