在vb.net中的listview中搜索项目 [英] Search items in listview in vb.net
本文介绍了在vb.net中的listview中搜索项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在listview中搜索包含重复字符串的文本,我还需要在vb的listview中返回所有匹配的字符串。 net。
例如
Hi,
Is there is any possibilities to search a text in listview which contains duplicates string also i need to return all matched strings in the listview in vb.net.
For e.g
Name Size Date Format
978945251.pdf.ssdswew 37Mb 3/7/2013 ssdswew
978945251.pdf.ssdsdsddew 37Mb 3/7/2013 ssdsdsddew
978945270.pdf.ssdswew 37Mb 3/7/2013 ssdswew
978945251.pdf.ssdghhsdde37Mb 3/7/2013 ssdsdghgfhsddew
只需返回
Need to return only
978945251.pdf.ssdswew 37Mb 3/7/2013 ssdswew
978945251.pdf.ssdsdsddew 37Mb 3/7/2013 ssdsdsddew
978945251.pdf.ssdghhsdde37Mb 3/7/2013 ssdsdghgfhsddew
谢谢
Sivasankaran G
Thanks
Sivasankaran G
推荐答案
嗨试试这样,
hi try this way,
Public Class Form1
Public output As New List(Of Class1)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim index As Integer
Dim row1 As String() = {"978945251.pdf.ssdswew", "37Mb", "3/7/2013", "ssdswew"}
Dim row2 As String() = {"978945251.pdf.ssdsdsddew", "37Mb", "3/7/2013", "ssdsdsddew"}
Dim row3 As String() = {"978945270.pdf.ssdswew", "37Mb", "3/7/2013", "ssdswew"}
Dim row4 As String() = {"978945251.pdf.ssdghhsdde", "37Mb", "3/7/2013", "ssdsdghgfhsddew"}
Dim lst As ListViewItem
lst = New ListViewItem(row1)
ListView1.Items.Add(lst)
lst = New ListViewItem(row2)
ListView1.Items.Add(lst)
lst = New ListViewItem(row3)
ListView1.Items.Add(lst)
lst = New ListViewItem(row4)
ListView1.Items.Add(lst)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim temp As String = String.Empty
For Each lv As ListViewItem In ListView1.Items
temp = lv.SubItems(3).Text
If (Isfound(temp) = False) Then
output.Add(AdddistinctRow(lv))
End If
Next
End Sub
Public Function Isfound(ByVal val As String) As Boolean
Dim flag As Boolean = False
Dim index As Integer = 0
For index = 0 To output.Count - 1
If (output(index).Format.Equals(val) = True) Then
flag = True
End If
Next
Return flag
End Function
Public Function AdddistinctRow(ByVal lst As ListViewItem) As Class1
Dim obj As New Class1
obj.Name = lst.SubItems(0).Text
obj.Size = lst.SubItems(1).Text
obj.Dates = lst.SubItems(2).Text
obj.Format = lst.SubItems(3).Text
Return obj
End Function
End Class
根据你自己编写班级的要求,
As per your requirement to write your own class,
Public Class Class1
Private _name As String
Public Property Name() As String
Set(ByVal value As String)
_name = value
End Set
Get
Return _name
End Get
End Property
Private _Size As String
Public Property Size() As String
Get
Return _Size
End Get
Set(ByVal value As String)
_Size = value
End Set
End Property
Private _Date As DateTime
Public Property Dates() As DateTime
Get
Return _Date
End Get
Set(ByVal value As DateTime)
_Date = value
End Set
End Property
Private _Format As String
Public Property Format() As String
Get
Return _Format
End Get
Set(ByVal value As String)
_Format = value
End Set
End Property
End Class
问候和谢谢
sarva
regards and thanks
sarva
使用动态Listview运行?
PS:列表视图中的项目不使用子项目
To Use With A Dynamic Listview Run?
PS: The Items In The Listview Don't Use SubItems
这篇关于在vb.net中的listview中搜索项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文