Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 7-Jul-13 17:59pm
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 8-Jul-13 0:52am
   
Review my solution posted...
12345_abcde at 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

Rate this: bad
good
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.
 
Thanks,
 
Kuthuparakkal
  Permalink  
v2
Comments
12345_abcde at 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
0 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2014
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