可点击列表框打开文本文档 VB.NET
Clickable listbox to open text document VB.NET
这是我的代码
Dim InputStr As String = CrystalClearTextBox1.Text
For Each FileStr As String In IO.Directory.GetFiles("C:\Users\root\Desktop\databases", "*.txt")
If IO.File.ReadAllText(FileStr).IndexOf(InputStr) >= 0 Then
ListBox1.Items.Add(IO.Path.GetFileName(FileStr))
Else
ListBox1.Items.Add("No Results found!")
End If
Next
End Sub
此外,除了 .txt,是否可以添加 .csv、.sql?
我想要做的是当它 returns 它所在的文本文件时能够单击它并打开文本文件并滚动到该文本文件中单词所在的位置,是这个可能的?如果你愿意帮助我,我将不胜感激!
您有 2 个问题。我会给出第一个,然后为那个做一个不同的主题。
Dim files = New DirectoryInfo("your directory").GetFiles()
'set the data source
lsb.DataSource = files
'this will be the display in the listbox
lsb.DisplayMember = "Name"
'this is the full path for opening the file
lsb.ValueMember = "FullName"
用法-在列表框selectedIndexChanged事件中。
'this will open whatever program is need to open the document
Process.Start(lsv.SelectedValue.ToString)
这是我的代码
Dim InputStr As String = CrystalClearTextBox1.Text
For Each FileStr As String In IO.Directory.GetFiles("C:\Users\root\Desktop\databases", "*.txt")
If IO.File.ReadAllText(FileStr).IndexOf(InputStr) >= 0 Then
ListBox1.Items.Add(IO.Path.GetFileName(FileStr))
Else
ListBox1.Items.Add("No Results found!")
End If
Next
End Sub
此外,除了 .txt,是否可以添加 .csv、.sql?
我想要做的是当它 returns 它所在的文本文件时能够单击它并打开文本文件并滚动到该文本文件中单词所在的位置,是这个可能的?如果你愿意帮助我,我将不胜感激!
您有 2 个问题。我会给出第一个,然后为那个做一个不同的主题。
Dim files = New DirectoryInfo("your directory").GetFiles()
'set the data source
lsb.DataSource = files
'this will be the display in the listbox
lsb.DisplayMember = "Name"
'this is the full path for opening the file
lsb.ValueMember = "FullName"
用法-在列表框selectedIndexChanged事件中。
'this will open whatever program is need to open the document
Process.Start(lsv.SelectedValue.ToString)