Question: Please help, I am trying to use the below code to add data to a data grid view. The bolded part of the below code

Please help, I am trying to use the below code to add data to a data grid view. The bolded part of the below code is the specific part that I'm getting this error from, " System.ArgumenNullException: Value cannot be null. Parameter name: source'"

Public Class frmNameAndStates Structure SupremeCourt Dim firstName, lastName, president, state As String Dim yearAppoint, yearLeft As Integer End Structure Dim strCourt() As SupremeCourt

Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click Dim records() As String = IO.File.ReadAllLines("Justices.txt") ReDim strCourt(records.Count - 1) Dim line As String Dim data() As String

For i As Integer = 0 To records.Count - 1 line = records(i) data = line.Split(","c) strCourt(i).firstName = data(0) strCourt(i).lastName = data(1) strCourt(i).president = data(2) strCourt(i).state = data(3) strCourt(i).yearAppoint = CInt(data(4)) strCourt(i).yearAppoint = CInt(data(5))

'Test to see if output comes out correctly 'lstOutput.Items.Add(line) Next

If IO.File.Exists("BkupJustice.txt") Then IO.File.Delete("BkupJustice.txt") End If IO.File.Copy("Justices.txt", "BkupJustice.txt")

Dim sortQuery = From position In strCourt Let name = position.firstName & " " & position.lastName Let state = position.state Let result = name & " " & state Select result 'Create file If IO.File.Exists("Name&State.txt") Then IO.File.Delete("Name&State.txt") End If IO.File.WriteAllLines("Name&State.txt", sortQuery) End Sub

Private Sub btnPopulate_Click(sender As Object, e As EventArgs) Handles btnPopulate.Click

Dim dgvQuery = From item In strCourt Let firstName = item.firstName Let lastName = item.lastName Let pres = item.president Let state = item.state Let appointed = item.yearAppoint Let left = item.yearLeft Select firstName, lastName, pres, state, appointed, left

dgvOutput.DataSource = dgvQuery.ToList dgvOutput.CurrentCell = Nothing

dgvOutput.Columns("firstName").HeaderText = "First Name" dgvOutput.Columns("lastName").HeaderText = "Last Name" dgvOutput.Columns("president").HeaderText = "Appointing President" dgvOutput.Columns("state").HeaderText = "State" dgvOutput.Columns("yearAppoint").HeaderText = "Year Appointed" dgvOutput.Columns("yearLeft").HeaderText = "Year Left" End Sub End Class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!