У меня возникают проблемы с моим кодом. Это говорит в ошибке, что я должен положить New
в код, но я не знаю, где его поставить. Это полный код функции:VB.Net Data Grid View
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Try
Dim TA As New POSCanteenTableAdapters.ItemsTableAdapter
Dim TB = TA.GetDataByBarcode(TextBox1.Text)
If TB.Rows.Count = 0 Then
TextBox2.Text = ""
TextBox3.Text = ""
Button1.Enabled = False
Exit Sub
End If
Button1.Enabled = True
Dim IR As POSCanteen.ItemsRow = TB.Rows(0)
TextBox2.Text = IR.ItemName
TextBox3.Text = IR.SellPrice
Button2.Tag = IR
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IR As POSCanteen.ItemsRow = Button1.Tag
Dim RI As New Integer
Dim ItemLoc As Integer = -1
For RI = 0 To CDGV3.Rows.Count - 1
If IR.Barcode = CDGV3.Rows(RI).Cells(0).Value Then
ItemLoc = RI
Exit For
End If
Next
If ItemLoc = -1 Then
CDGV3.Rows.Add(IR.Barcode, IR.ItemName, IR.BuyPrice, IR.SellPrice, 1, IR.SellPrice)
Else
Dim ItemCount As Long = CDGV3.Rows(ItemLoc).Cells(4).Value
ItemCount += 1
Dim NewPrice As Decimal = IR.SellPrice * ItemCount
CDGV3.Rows(ItemLoc).Cells(4).Value = ItemCount
CDGV3.Rows(ItemLoc).Cells(5).Value = NewPrice
End If
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Предполагается добавить элемент в таблице данных, но он не будет из-за этой ошибки. Я не знаю, где его поставить, поскольку компилятор не говорит мне, где.
Это сообщение об исключении: Object reference not set to an instance of an object.
ГДЕ ЕСТЬ ПРИЧИНАТЬ? VS расскажет вам, в чем именно НИЧЕГО, просто используя мышь. – Plutonix
Со стороны на CDGV3.rows.add (IR.ItemName.IR.BuyPrice, Ir.SellPrice, 1, Ir.Sellprice) – GMSieghart
С помощью мыши над переменной 'IR' это' Nothing'? – OneFineDay