Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1306
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 30, 20222022-05-30T12:21:40+00:00 2022-05-30T12:21:40+00:00

vb.net – json file search with output found in datagridview

  • 0

[ad_1]

The form has a text field and a datagridview. It is necessary, without displaying the entire contents of the json file in the DataGridView, to search for the json file and display the search result in the DataGridView.You need to search by the UserName tag. You need to start typing either the first or last name in the text field and in the datagridview display the result of the found

How to read text file in dataGridView I know:

Imports System.IO
Imports Newtonsoft.Json

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim result = JsonConvert.DeserializeObject(Of List(Of Users))(File.ReadAllText("D:\Users.json"))
        DataGridView1.DataSource = result
    End Sub

      Public Class Users
        Public Property ID() As Integer
        Public Property UserName() As String
        Public Property Login() As String
        Public Property Title() As String
        Public Property Dep() As String
        Public Property Mail() As String
        Public Property Phone() As String
    End Class

End Class

I also know how to do a file search. Only for some reason the result displays – the first element found:

  Dim json As String = File.ReadAllText("D:\Users.json")
        Dim objectList = JsonConvert.DeserializeObject(Of List(Of Users))(json)
        Dim foundItem = objectList.Where(Function(underscore) underscore.UserName.Contains("Tom")).FirstOrDefault()

        If foundItem IsNot Nothing Then
            MessageBox.Show(foundItem.UserName)

        Else
            MsgBox("none")
        End If

And the actual contents of the json file itself:

[
{
"id":"1",
"UserName":"Fred Smith",
"Login":"f.smith",
"Title":"engineer",
"Dep":"IT infrastcomcture",
"Mail":"[email protected]",
"Phone":"111",
},
{
"id":"2",
"UserName":"Ben Taylor",
"Login":"b.taylor",
"Title":"programmer",
"Dep":"IT infrastcomcture",
"Mail":"[email protected]",
"Phone":"100",
},
{
"id":"3",
"UserName":"Steve Harris",
"Login":"s.harris",
"Title":"System Administrator",
"Dep":"IT infrastcomcture",
"Mail":"[email protected]",
"Phone":"263",
},
{
"id":"4",
"UserName":"Tom Walker",
"Login":"t.walker",
"Title":"engineer",
"Dep":"IT infrastcomcture",
"Mail":"[email protected]",
"Phone":"263",
},
{
"id":"5",
"UserName":"Tom Davis",
"Login":"t.davis",
"Title":"engineer",
"Dep":"IT infrastcomcture",
"Mail":"[email protected]",
"Phone":"200",
},
{
"id":"6",
"UserName":"Ben Walker",
"Login":"b.walker",
"Title":"System Administrator",
"Dep":"IT infrastcomcture",
"Mail":"[email protected]",
"Phone":"167",
},
]

[ad_2]

  • 0 0 Answers
  • 11 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 4994 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1084 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1028 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.