其他信息:索引-1没有值。
我正在创建数据处理程序,此form3包含一个DGV,该DGV显示了来自我的MS Access DB的数据,另一个DGV1包含了一个对象列表中的项目。
问题是,当我单击DGV1的任何项目时,都会显示错误并程序中断
我在另一个程序上尝试过,效果很好
我将在此处粘贴表单代码
Imports System.IO
Imports Newtonsoft.Json
Public Class Form3
Public Shared d As devis = New devis() 'creatig devis
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataATDataSet.DataArticl' table. You can move, or remove it, as needed.
Me.DataArticlTableAdapter.Fill(Me.DataATDataSet.DataArticl) 'fill DGV with data in db
devisBindingSource.DataSource = d.listArticle 'DGV1 data source list of article in devis d
DataGridView1.DataSource = devisBindingSource
End Sub
Private sRef As String 'variable to put selected row values
Private sNomArticle As String
Private sPU As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sRef = DataArticlDataGridView.CurrentRow.Cells(0).Value
sNomArticle = DataArticlDataGridView.CurrentRow.Cells(1).Value
sPU = DataArticlDataGridView.CurrentRow.Cells(2).Value
d.addArticle(sRef, sNomArticle, CDbl(sPU), CDbl(TextBox1.Text)) 'adding article to list
DataGridView1.DataSource = Nothing 'refreshing data source
DataGridView1.DataSource = devisBindingSource
DataGridView1.Refresh()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim savePath As String = Directory.GetCurrentDirectory + "/projects/" + Form1.projectName 'saving folder
File.WriteAllText(savePath + "/devis.json", JsonConvert.SerializeObject(d)) 'serialize object in json
MsgBox("Saved")
End Sub
End Class