Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Else
Continue For

End If
Next

but it doesnt work, why is it so?

thanks in advance!
Posted
Comments
Sergey Alexandrovich Kryukov 7-Jul-13 23:05pm    
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...
—SA
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.
Kuthuparakkal 8-Jul-13 0:52am    
Review my solution posted...
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
Me.dgvModStud.Rows.Add(row.Cells(i).Value)
Else
Continue For
Me.dgvModStud.Rows.Add(obj)
End If
Next

Next

it's not working though ><

1 solution

Try this:
VB
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.


Thanks,

Kuthuparakkal
 
Share this answer
 
v2
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900