用空字符串替换重复项 [英] replacing duplicates with empty string

查看:115
本文介绍了用空字符串替换重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2列的datagridview,标题:ModuleCode,AdminNo(学生编号)

i想要填充:

EG1001 s1

-blank- s2

-blank- s3



EG1002 S2

-blank- S4


我目前的代码:



i have datagridview with 2 columns, headings: ModuleCode, AdminNo(which is students number)
i want to populate:
EG1001 s1
-blank- s2
-blank- s3

EG1002 S2
-blank- S4

with my current code:

Dim j As Integer

       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





仅应用我的第一个模块。但是对于其他人来说它没有。

i猜我的j有问题。

我怎么能让它递增?

提前谢谢!



only my first modulecode is applied. but for the others it doesnt.
i guess something wrong with my j.
how can i get it incrementing?
Thanks in advance!

推荐答案

尝试这样的事情:



Try something like this:

Dim currentModuleCode As String = String.Empty

For i = 1 To dgvModStud.Rows.Count - 1

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

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

    End If

Next i





然后你不必担心增量j。此外,它意味着当模块代码更改时,您将获得一个条目,但该代码的其余部分应为空白。



这也意味着如果列表如果代码重新出现,它的代码可见,所以它不会被排序,因此它看起来不像是错误的代码。



Then you do not need to worry about increment j. Also it means that when the module code changes you will get an entry for it, but the rest for that code should be blank.

This also means that if the list is not ordered then if a code re-occurs it will have a its code visible so it does not appear as if it is under the wrong one.


这篇关于用空字符串替换重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆