如何确定列表框中的多个字符串? [英] How to Determine Multiple Strings in Listbox?

查看:90
本文介绍了如何确定列表框中的多个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个简单的问题,但我的方式似乎冻结我的程序没有错误。



我想确定是否一个字符串被添加到我的列表框中的子项目,如果是这样就删除它..



这里是我试图使用的代码



This may seem to be a simple question but the way I am going about it seems to freeze my program with no error.

I am looking to determine if a string is being added to a subitem in my listbox and if so to remove it..

here is the code I am trying to use

Dim hiber As String = "hiberfil.sys"
        Dim FXSAPI As String = "FXSAPIDebugLogFile.txt"
        Dim setup1 As String = "setup-a.bin"
        Dim setup2 As String = "setup-b.bin"
  For Each ListViewItem As ListViewItem In resultsbox.Items
                                If ListViewItem.SubItems(1).Text = hiber or FXSAPI or setup1 or setup2 Then
                                    ListViewItem.Remove()
                                End If
                            Next







我可以用其他方式实现这个目标吗?...



提前谢谢




what other way can i achieve this?..

thank you in advance

推荐答案

你的if语句被严重搞砸了。你不能列出一个项目列表(你正在他们!)来比较一个变量。您必须单独将变量与列表中的每个项目进行比较。 (顺便说一句:你的ListViewItem变量名是一个可怕的选择,因为它与一个知名类的名称完全相同。只需称它为 item 并完成它。)



Your if statement is seriously screwed. You cannot make a list of items (you''re OR''ing them!) to compare a single variable to. You MUST compare the variable to each item in the list seperately. (BTW: Your ListViewItem variable name is a TERRIBLE choice since it''s exactly the same as the name of a well-known class. Just call it item and be done with it.)

If ListViewItem.SubItems(1).Text = hiber or FXAPI or ...



成为


becomes

Dim subItem As String = ListViewItem.SubItems(1).Text
If subItem = hiber Or subItem = FXSAPI Or subitem = setup1 Or subItem = setup2 Then ...





这是一个VB.NET(或任何其他语言)101件事。你真的需要在VB.NET上学习一本初学者书并完成它。



This is a VB.NET (or any other language) 101 thing. You REALLY need to pickup a beginners book on VB.NET and work through it.


这篇关于如何确定列表框中的多个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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