如何确定列表框中的多个字符串?

编程入门 行业动态 更新时间:2024-10-24 16:31:24
本文介绍了如何确定列表框中的多个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这似乎是一个简单的问题,但我的方式似乎冻结我的程序没有错误。 我想确定是否一个字符串被添加到我的列表框中的子项目,如果是这样就删除它.. 这里是我试图使用的代码

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.

更多推荐

如何确定列表框中的多个字符串?

本文发布于:2023-08-07 13:55:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   字符串   框中   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!