Click here to Skip to main content
14,971,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Need help, First not good in english,
I have listview displaying items from text file from designated directory (folder), i want search box and (TextBox1) and cmdButton (Button1) to search and display all items I search in third column or the ID Number.

EX:

Column 1: Date and Time:
Column 2: Name:
Column 3: ID Number:

08-08-2017 06:06:00, John Lucas, 1010000
08-08-2017 07:00:00, April Dun, 1010023
08-08-2017 08:45:00, Kevin Elmo, 1010014
08-08-2017 09:06:00, John Lucas, 1010000
08-08-2017 10:24:00, Ed Olivia, 1010012
08-08-2017 11:47:00, John Lucas, 1010000
08-08-2017 12:56:00, Liza Ben, 1010001

I want to display data (items) of John Lucas by searching ID Number and display it in listview (another listview)

What I have tried:

'This is the code to display my items from text file only, I don't have any idea and Im asking for some help from you, TIA.'

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load, MyBase.DockChanged
lvDETAILS.View = View.Details
        lvDETAILS.Columns.Add("Date/Time:", 220, HorizontalAlignment.Left)
        lvDETAILS.Columns.Add("Employee Name:", 280, HorizontalAlignment.Left)
        lvDETAILS.Columns.Add("ID Number:", 120, HorizontalAlignment.Left)
        lvDETAILS.Columns.Add("Department:", 250, HorizontalAlignment.Left)
        lvDETAILS.Columns.Add("User Type:", 200, HorizontalAlignment.Left)
        lvDETAILS.Columns.Add("ESD Check Result:", 200, HorizontalAlignment.Left)

        Dim File_Name As String = "D:\esdcheck\DET.dll"
        Dim objReader As New IO.StreamReader(File_Name)
        Dim newarray(6) As String
        Dim DateTime As String
        Dim Name As String
        Dim IDNum As String
        Dim Department As String
        Dim UserType As String
        Dim ESDResult As String

        Do While objReader.Peek <> -1
            newarray = objReader.ReadLine().Split(",")
            DateTime = newarray(0)
            Name = newarray(1)
            IDNum = newarray(2)
            Department = newarray(3)
            UserType = newarray(4)
            ESDResult = newarray(5)
            Dim x As Integer = lvDETAILS.Items.Add(New ListViewItem(New String() {DateTime})).Index 'Para sa Listview unang Column depende sa base sa index
            lvDETAILS.Items.Item(x).SubItems.Add(Name) 'yung 'x' po na yun ay number of index na nakaset per column., ilalagay sa second column depende sa index
            lvDETAILS.Items.Item(x).SubItems.Add(IDNum) 'sunod sunod lang po ang pag lagay depende sa dami ng column
            lvDETAILS.Items.Item(x).SubItems.Add(Department) 'yeah
            lvDETAILS.Items.Item(x).SubItems.Add(UserType) 'yeah
            lvDETAILS.Items.Item(x).SubItems.Add(ESDResult) 'yeah !!! eto na yung last!
End Sub
Posted
Updated 14-Aug-17 21:27pm
Comments
Ralf Meier 15-Aug-17 2:23am
   
I would suggest this :
If you have an Input in your TextBox : clear your 2nd ListView , iterate through your 1st ListView and look if you find at the Name-SubItem a match. If Yes transfer the relevant data to your 2nd ListView.

Your best solution is to use a control that supports data binding & filtering. Whilst it is possible and overly involved, the ListView is not really suitable for this purpose.

However the DataGridView is designed for the task that you want to achieve. This CodeProject article shows you exactly how to achieve what you want: A Detailed Data Binding Tutorial[^]
   
Thank you for the reply

Im using Visual Studio 2017 VB.net - it's C#
   
Comments
Richard Deeming 15-Aug-17 14:42pm
   
If you want to reply to a solution, use the "Have a Question or Comment?" button under that solution.

DO NOT post your comment as a new "solution"!

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900