Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to dislay the text file visitation.txt in a dataview grid, however, ,my c

ID: 3723671 • Letter: I

Question

I need to dislay the text file visitation.txt in a dataview grid, however, ,my code isnt working. Can anyone assist with this?

Public Class FrmVisitation
    Dim visitors() As String = IO.File.ReadAllLines("visitation.txt")
    Private Sub BtnClsoe_Click(sender As Object, e As EventArgs) Handles BtnClsoe.Click
        Me.Close()
    End Sub

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

        Dim query = From line In visitors
                    Let data = line.Split(","c)
                    Let lastname = data(0)
                    Let firstname = data(1)
                    Let age = CInt(data(2))
                    Let SSClass = CInt(data(2))
                    Select lastname, firstname, age, SSClass

    End Sub

    Private Sub dvgVisitors_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dvgVisitors.CellContentClick

        dvgVisitors.DataSource = Query.ToList()
        dvgVisitors.CurrentCell = Nothing
    End Sub
End Class

Explanation / Answer

Imports System.Drawing
Imports System.Windows.Forms
Imports System.Data

Public Class StartEventArgs
Inherits System.EventArgs

'Provide one or more constructors, as well as fields and
'accessors for the arguments.

End Class

Public Class FrmVisitation
Dim visitors() As String = System.IO.File.ReadAllLines("visitation.txt")
Private Sub BtnClose_Click(sender As Object, e As StartEventArgs)
  
End Sub

Private Sub FrmVisitation_Load(sender As Object, e As StartEventArgs)

Dim query = From line In visitors
Let strarr = line.Split(","c),
Let lastname = data(0),//these(Use of "Let") are deprecated..change it
Let firstname = data(1),
Let age = CInt(data(2)),
Let SSClass = CInt(data(2)),
Select lastname, firstname, age, SSClass

End Sub

Private WithEvents dvgVisitors As New DataGridView()
Private Sub dvgVisitors_CellContentClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs)

dvgVisitors.DataSource = Query.ToList()
dvgVisitors.CurrentCell = Nothing
End Sub
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote