Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.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
 
Thanks
Sivasankaran G
Posted 14-Mar-13 4:54am
Edited 14-Mar-13 4:57am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 

regards and thanks
sarva
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 309
2 BillWoodruff 174
3 /\jmot 160
4 Suraj Sahoo | Coding Passion 160
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 14 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100