Hi,
I have a windows form named as FrmInvoiceEdit. In this form saved Invoice is displayed in datagridview1 by searching Invoice no. in text box which is named as TxtInvoiceNo.
The code is
I have another form named as FrmAddItemsNew for adding, editing items. When AddItem button is clicked this form is open.
Add button code is
but when I click this button the error is shown as -
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
The code for editing row is
And when I select row and press edit button to edit row the error is shown as -
Additional information: Object reference not set to an instance of an object.
I want user to add, edit and delete the item from Invoice.
When he add, edit and delete the item firstly it should be populated in datagridview and when he press button Save it should be saved to the database, but if he add, edit and delete the item but he want to cancel these changes by Cancel Button is pressed it should not be saved to the database, it should be only affect the datagridview.
I have seen this in professional softwares which are in market.
I searched many video but cannot find any answer for this.
any help will be appreciated.
thanks.
I have a windows form named as FrmInvoiceEdit. In this form saved Invoice is displayed in datagridview1 by searching Invoice no. in text box which is named as TxtInvoiceNo.
The code is
VB.NET:
Dim cmd As New OleDbCommand("SELECT * from TblTest WHERE InvoiceID = @InvoiceID", con)
With cmd.Parameters
.Add("@InvoiceID", OleDbType.VarChar, 50).Value = TxtInvoiceNo.Text
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
da.SelectCommand = cmd
dt.Clear()
da.Fill(dt)
DataGridView1.DataSource = dt
Add button code is
VB.NET:
FrmInvoiceEdit.DataGridView1.Rows.Add(TxtInvoiceID.Text, TxtID.Text, CmbProductName.Text, TxtHSN.Text, TxtSerial.Text, TxtUnit.Text, TxtQty.Text, TxtInclRate.Text, TxtBaseRate.Text, TxtAmount.Text, TxtGST.Text, TxtGSTAmt.Text, TxtTotal.Text)
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
The code for editing row is
VB.NET:
Private Sub Editrecord()
If MsgBox("Edit Product Entry?", vbYesNo + vbQuestion) = vbYes Then
FrmAddItemsNew.Show()
Dim i As Integer
i = DataGridView1.CurrentCell.RowIndex
FrmAddItemsNew.TxtID.Text = DataGridView1.Rows(i).Cells(1).Value.ToString()
FrmAddItemsNew.CmbProductName.Text = DataGridView1.Rows(i).Cells(2).Value.ToString()
FrmAddItemsNew.TxtHSN.Text = DataGridView1.Rows(i).Cells(3).Value.ToString()
FrmAddItemsNew.TxtSerial.Text = DataGridView1.Rows(i).Cells(4).Value.ToString()
FrmAddItemsNew.TxtUnit.Text = DataGridView1.Rows(i).Cells(5).Value.ToString()
FrmAddItemsNew.TxtQty.Text = DataGridView1.Rows(i).Cells(6).Value.ToString()
FrmAddItemsNew.TxtInclRate.Text = DataGridView1.Rows(i).Cells(7).Value.ToString()
FrmAddItemsNew.TxtBaseRate.Text = DataGridView1.Rows(i).Cells(8).Value.ToString()
FrmAddItemsNew.TxtAmount.Text = DataGridView1.Rows(i).Cells(9).Value.ToString()
FrmAddItemsNew.TxtGST.Text = DataGridView1.Rows(i).Cells(10).Value.ToString()
FrmAddItemsNew.TxtGSTAmt.Text = DataGridView1.Rows(i).Cells(11).Value.ToString()
FrmAddItemsNew.TxtTotal.Text = DataGridView1.Rows(i).Cells(12).Value.ToString()
End If
Additional information: Object reference not set to an instance of an object.
I want user to add, edit and delete the item from Invoice.
When he add, edit and delete the item firstly it should be populated in datagridview and when he press button Save it should be saved to the database, but if he add, edit and delete the item but he want to cancel these changes by Cancel Button is pressed it should not be saved to the database, it should be only affect the datagridview.
I have seen this in professional softwares which are in market.
I searched many video but cannot find any answer for this.
any help will be appreciated.
thanks.