Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions