搜索文本文件并将匹配结果放入列表框中 [英] Search text file and put matching results in listbox

查看:44
本文介绍了搜索文本文件并将匹配结果放入列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VB.NET 项目,其中有一个表单,其中有一个 TextBox 控件、一个 ListBox 控件和一个包含客户端电子邮件的 Outlook 文件夹路径列表的外部文本文件.

I have a VB.NET project in which there is a form where there is a TextBox control, a ListBox control and an external text file that contains a list of outlook folder paths for client emails.

基本上,用户在文本框中输入客户的名称和/或他们的唯一参考编号,然后按下搜索按钮(是的 - 我知道我可以在他们输入时显示结果,我想要一个按钮!)并将文本文件中的公司名称或序列号的匹配结果与 Outlook 电子邮件文件夹的完整路径一起放入列表框中.

Essentially, the user enters into the text box the name of a client and/or their unique reference number, presses the search button (yes - I know I could make the results appear as they type, I want a button!) and it comes up with the matching results for the company name or serial number that are in the text file and puts them in the list box, with the full path of the outlook email folder.

例如:

如果我在文本框中输入:06967759-274D-40B2-A3EB-D7F9E73727D7"

If I put into the textbox: "06967759-274D-40B2-A3EB-D7F9E73727D7"

它会将以下结果放入列表框:

It would put the following result into the listbox:

EIS 管理员\联系人{06967759-274D-40B2-A3EB-D7F9E73727D7}"

"EIS Admin\Contacts{06967759-274D-40B2-A3EB-D7F9E73727D7}"

然后用户可以转到该文件夹​​并找到电子邮件.

And the user can then go to that folder and find the email(s).

我已经对我自己的代码和从网上粘贴的代码进行了多次修改,但有同样问题的人,只是让 Visual Studio 没有抛出错误,运行代码并且没有运气,除了清除列表框,并且不显示任何类型的匹配结果.

I have gone through several revisions both of my own code and code pasted from online with people having the same issue, only to have Visual Studio throw no errors, run the code and have no luck, with it doing nothing but clearing the list box, and not showing matching results of any kind.

我知道这可能是一个重复的问题,但我非常困惑,无法解决任何问题,需要一些有关我的问题的帮助.

I understand this may be a repeat question but I am extremely confused, can't get anything to work and need some help regarding my issue.

这是当前代码(来自在线 - 不是我的):

Here is the current code (from online - not mine):

lbx_OFL_Results.Items.Clear()
Dim i As Integer
For i = 0 To lbx_OFL_Results.Items.Count - 1
    If i > lbx_OFL_Results.Items.Count - 1 Then Exit For
    If Not lbx_OFL_Results.Items(i).Contains(tbx_FindText.Text) Then
        lbx_OFL_Results.Items.Remove(lbx_OFL_Results.Items(i))
        i -= 1
    End If
Next

列表框名为lbx_OFL_Results"文本框被称为tbx_FindText"

The list box is called "lbx_OFL_Results" The textbox is called "tbx_FindText"

我首先清除所有项目的列表框(当表单加载时,它将填充列表框将文本文件的所有行,所以我需要清除它).

I start by clearing the list box of all items (when the form loads, it fills the list box will all lines of the text file, so I need to clear it).

表单加载事件代码:

Dim lines1() As String = IO.File.ReadAllLines("C:\ProgramData\WPSECHELPER\.data\Outlook Folder Wizard\outlookfolders.txt")
lbx_OFL_Results.Items.AddRange(lines1)

对于其余的代码,它似乎在进行某种形式的排序搜索",然后删除任何多余的结果.

For the rest of the code it seems to be doing some form of a 'sort search' then removing any excess results.

如果有人可以建议对我的代码进行编辑或新代码,那就太好了.

If anyone can suggest edits to my code, or new code then that would be sublime.

谢谢.

推荐答案

感谢@Jimi 的回答.

Thanks to @Jimi for the answer.

代码:

listbox.Items.Clear() 
listbox.BeginUpdate() 
For i as Integer = 0 To lines1().Length - 1 
If lines1(i).Contains(searchbox.Text) Then 
    listbox.Items.Add(lines1(i)) 
End If 
Next 
listbox.EndUpdate()

我还有一个问题可以解决如何使此搜索不区分大小写.可以在此处找到.

I have another question which solves how to make this search non case-sensitive. It can be found here.

这篇关于搜索文本文件并将匹配结果放入列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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