用string.empty替换重复值 [英] replace duplicate values with string.empty
问题描述
我有数据填写:
EG1001 S1
EG1001 S2
EG1001 S3
< br $>
i希望它达到:
EG1001 s1
-blank- s2
- blank-s3
EG1002 S2
-blank- S4
填充在datagridview。
尝试使用此代码:
Dim i As Integer
For i = 0 to dgvModStud.Rows.Count - 1
如果dgvModStud.Rows(i).Cells(0).Value = True则
dgvModStud.Rows (i).Cells(0).Value = String.Empty
否则
继续使用
结束如果
下一页
但它不起作用,为什么会这样?
提前感谢!
试试这个:
Dim 表作为 新 DataTable
' 在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 新 DataTable
DistinctCol = 新 字符串(){ < span class =code-string> MyKey}
Dim i 正如 整数
dtDistinct = table.DefaultView.ToTable( True ,DistinctCol)
Dim foundRows() As DataRow
对于 每个行作为 DataRow 在 dtDistinct.Rows
strKey = row( 0 )。ToString()
foundRows = table。选择( MyKey ='& strKey& ')
如果(foundRows.Length> 1 )那么
对于 i = 1 foundRows.GetUpperBound( 0 )
foundRows(i)( MyKey)= ' 或-blank-无论你喜欢什么
下一页 i
结束 如果
下一步 row
' 现在您可以使用数据表table作为源代码对于gridview。
谢谢,
Kuthuparakkal
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!
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
这篇关于用string.empty替换重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!