• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

When a new product add, the Total in the row is not appear vb2005

These is a code needed to make calculation for rows and column the  code work when i insert it to  Private Sub Norders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum

The problem  is
1.When a new product add the  Total in the row is not appear


All my code and photo of the form are below
Public Class Norders
 
   
    Private Sub Norders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Orders' table. You can move, or remove it, as needed.
        Me.OrdersTableAdapter.Fill(Me.NicolaouDBDataSet.Orders)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
        Me.OrdersDetailsTableAdapter.Fill(Me.NicolaouDBDataSet.OrdersDetails)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NicolaouDBDataSet.Products)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
        Me.SuppliersTableAdapter.Fill(Me.NicolaouDBDataSet.Suppliers)
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum
    End Sub
 
 
    Private Sub OrdersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.OrdersBindingSource.EndEdit()
        Me.OrdersTableAdapter.Update(Me.NicolaouDBDataSet.Orders)
 
    End Sub
 
    Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
        OrdersBindingSource.MoveNext()
    End Sub
 
    Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
        OrdersBindingSource.MovePrevious()
    End Sub
 
    Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
        OrdersBindingSource.MoveLast()
    End Sub
 
    Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
        OrdersBindingSource.MoveFirst()
    End Sub
 
    Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
        OrdersBindingSource.AddNew()
 
 
    End Sub
 
    Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
        OrdersBindingSource.RemoveCurrent()
    End Sub
 
    Private Sub OrdersDetailsBindingSourceBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.OrdersDetailsBindingSource.EndEdit()
        Me.OrdersDetailsTableAdapter.Update(Me.NicolaouDBDataSet.OrdersDetails)
       
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text
        dr("productname") = ProductNameTextBox1.Text
 
        ds.Tables("OrdersDetails").Rows.Add(dr)
 
    End Sub
 
 
 
    
 
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text
        dr("productname") = ProductNameTextBox1.Text
 
        ds.Tables("OrdersDetails").Rows.Clear()
    End Sub
 
    Private Sub OrdersDetailsDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles OrdersDetailsDataGridView.CellContentClick
     
    End Sub
 
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
       
    End Sub
End Class

Open in new window

untitled.PNG
untitled2.PNG
0
demoniumz
Asked:
demoniumz
  • 40
  • 21
1 Solution
 
Wayne Taylor (webtubbs)Commented:
You should add your summing code to the RowsAdded event of the DataGridView.

Wayne
0
 
demoniumzAuthor Commented:
where  do you mean  in the button Add?
0
 
Wayne Taylor (webtubbs)Commented:
No, I mean in the RowAdded event of the DataGridView.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Wayne Taylor (webtubbs)Commented:
   Private Sub OrdersDetailsDataGridView_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles OrdersDetailsDataGridView.RowsAdded
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum
    End Sub
0
 
demoniumzAuthor Commented:
i cant find it
0
 
demoniumzAuthor Commented:
FIND IT testing but error when add a new product Object reference not set to an instance of an object
ds.Tables("OrdersDetails").Rows.Add(dr)
0
 
Wayne Taylor (webtubbs)Commented:
0
 
demoniumzAuthor Commented:
page not open
0
 
Wayne Taylor (webtubbs)Commented:
OK, I'll post it again.....

   Private Sub OrdersDetailsDataGridView_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles OrdersDetailsDataGridView.RowsAdded
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum
    End Sub
0
 
demoniumzAuthor Commented:
 Private Sub OrdersDetailsDataGridView_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles OrdersDetailsDataGridView.RowsAdded
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum

    End Sub
0
 
Wayne Taylor (webtubbs)Commented:
Yes?
0
 
demoniumzAuthor Commented:
i have allready find it add it  nut i get error when a  new product added
Object reference not set to an instance of an object

(code line error is these) ds.Tables("OrdersDetails").Rows.Add(dr)


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text
        dr("productname") = ProductNameTextBox1.Text
 
        ds.Tables("OrdersDetails").Rows.Add(dr)
 
    End Sub

Open in new window

0
 
Wayne Taylor (webtubbs)Commented:
When you get the error, hover over the objects with the mouse and see what they are set to. That'll tell us which object is "Nothing".
0
 
demoniumzAuthor Commented:
i cant found any object that is Nothing  would you like to upload you the forms  somwhere to help me
0
 
demoniumzAuthor Commented:
can u?
0
 
demoniumzAuthor Commented:
sage  what i can do to coreect the eerror
0
 
demoniumzAuthor Commented:
sage all the objext is set to someting so why i get these error
0
 
Wayne Taylor (webtubbs)Commented:
My username is webtubbs. Sage is my rank.

>>would you like to upload you the forms  somwhere to help me

No, that's fine.

Do you get the error when you remove the code from the RowsAdded event?
0
 
Wayne Taylor (webtubbs)Commented:
Otherwise, please post the entire error, including call stack.
0
 
demoniumzAuthor Commented:
i get the error when i add the code to RowsAdded event
untitled.PNG
0
 
Wayne Taylor (webtubbs)Commented:
When you get the error, go to Debug > Windows > Locals, the capture and post a screen shot of that window.

This window will also tell you which object is set to Nothing, which absolutely *is* the case, otherwise you wouldn't be getting that error.
0
 
Wayne Taylor (webtubbs)Commented:
Failing that, remove the code from the RowsAdded event, and put it in the "Add" button click event, after you have updated the DataTable.
0
 
demoniumzAuthor Commented:
these one ?
untitled3.PNG
0
 
demoniumzAuthor Commented:
when add the code to add button in the load i  dont get nothing in add a new product the total is  appear in the rows and in the column total.but when the rows clear the total remain the same
0
 
demoniumzAuthor Commented:
i have find that ds container is nothing
0
 
demoniumzAuthor Commented:
i have find that ds container is nothing what i can dowebtubbs?
0
 
Wayne Taylor (webtubbs)Commented:
Why is it Nothing? Have you changed any other code besides the RowsAdded event?
0
 
demoniumzAuthor Commented:
no
Public Class Norders
    Private im As Object
 
    Private Sub Norders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Orders' table. You can move, or remove it, as needed.
        Me.OrdersTableAdapter.Fill(Me.NicolaouDBDataSet.Orders)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
        Me.OrdersDetailsTableAdapter.Fill(Me.NicolaouDBDataSet.OrdersDetails)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NicolaouDBDataSet.Products)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
        Me.SuppliersTableAdapter.Fill(Me.NicolaouDBDataSet.Suppliers)
 
 
 
    
    End Sub
 
 
   
 
 
    Private Sub OrdersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.OrdersBindingSource.EndEdit()
        Me.OrdersTableAdapter.Update(Me.NicolaouDBDataSet.Orders)
 
    End Sub
 
    Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
        OrdersBindingSource.MoveNext()
    End Sub
 
    Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
        OrdersBindingSource.MovePrevious()
    End Sub
 
    Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
        OrdersBindingSource.MoveLast()
    End Sub
 
    Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
        OrdersBindingSource.MoveFirst()
    End Sub
 
    Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
        OrdersBindingSource.AddNew()
 
 
    End Sub
 
    Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
        OrdersBindingSource.RemoveCurrent()
    End Sub
 
    Private Sub OrdersDetailsBindingSourceBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.OrdersDetailsBindingSource.EndEdit()
        Me.OrdersDetailsTableAdapter.Update(Me.NicolaouDBDataSet.OrdersDetails)
 
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
        Dim orderdetailstable As New DataTable
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text
        dr("productname") = ProductNameTextBox1.Text
 
        ds.Tables("OrdersDetails").Rows.Add(dr)
        
    End Sub
 
 
 
 
 
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text
        dr("productname") = ProductNameTextBox1.Text
 
        ds.Tables("OrdersDetails").Rows.Clear()
 
    End Sub
 
    Private Sub OrdersDetailsDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles OrdersDetailsDataGridView.CellContentClick
 
    End Sub
 
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
 
    End Sub
 
    Private Sub OrderIDDataGridViewTextBoxColumn_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles OrderIDDataGridViewTextBoxColumn.Disposed
 
    End Sub
 
    Private Sub OrdersDetailsDataGridView_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles OrdersDetailsDataGridView.RowsAdded
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum
        OrdersDetailsDataGridView.Refresh()
 
    End Sub
End Class

Open in new window

0
 
demoniumzAuthor Commented:
what i can do  why i can declare it what is changed? The product now is added the total is ok  but when the product is added after 1-2 seconds i get again the error
0
 
Wayne Taylor (webtubbs)Commented:
OK, so again, if you remove the code from the RowsAdded event, do you still get the error??
0
 
demoniumzAuthor Commented:
nop

0
 
demoniumzAuthor Commented:
but why these error
0
 
demoniumzAuthor Commented:
i tell you  to upload the form  to  see what happend  but you  dont want
0
 
Wayne Taylor (webtubbs)Commented:
Try taking out the Refresh code from the RowsAdded event.
0
 
Wayne Taylor (webtubbs)Commented:
>>i tell you  to upload the form  to  see what happend  but you  dont want

If you think it'll help, go ahead. I can't promise anything though.
0
 
demoniumzAuthor Commented:
when  added to add buton  click  is work but the total is not appear from the time that the form is  load
0
 
demoniumzAuthor Commented:
when  the refresh command delete the product is not added  just get error when the refresh command is there the comand added but in 2-3 second the problem stop the aplication
0
 
demoniumzAuthor Commented:
ok  here is the  link  you can download it  http://rapidshare.com/files/224781499/New_Folder__5_.rar.html

pls help me i stuck  here for 2-3 days now
0
 
demoniumzAuthor Commented:
i  go to  work now i  wait news  what  you make thnks for help i apreciate it

regards demoniumz
0
 
demoniumzAuthor Commented:
webtubbs: thnks  for help:)
0
 
Wayne Taylor (webtubbs)Commented:
I'm unable to download that file. Please zip it up and upload it at www.ee-stuf.com.
0
 
demoniumzAuthor Commented:
back  ok i try to update in in Experts exchange
0
 
demoniumzAuthor Commented:
i have problems to  update the file in EE
0
 
demoniumzAuthor Commented:
databse
NicolaouDB.mdb
0
 
demoniumzAuthor Commented:
my aplicateion
0
 
demoniumzAuthor Commented:
after several problem in uploading is here in zip  format pls download
http://uploading.com/files/AIWEX8AD/Nicolaou.zip.html
0
 
demoniumzAuthor Commented:
webtubbs i wait your news
0
 
Wayne Taylor (webtubbs)Commented:
OK, downloading now. And please take the time to read comments posted properly. I did not say to upload it to EE, I said upload it to www.ee-stuff.com.
0
 
demoniumzAuthor Commented:
ok apologize
0
 
Wayne Taylor (webtubbs)Commented:
No probs.

OK, I've looked at your project, but I'm unable to get it working, and frankly, I'm not going to try. But I do have a few suggestions....

1) In the "Total" column of table "OrderDetails", set the Expression to "[UnitPrice]*[Quantity]" (without the quotes, of course).
2) Remove the RowsAdded event code.
3) Change your Add button code to this....
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        With CType(Me.OrdersDetailsBindingSource.AddNew(), DataRow)
            .Item("OrderID") = OrderIDTextBox.Text
            .Item("ProductID") = ProductIDComboBox.SelectedValue
            .Item("UnitPrice") = UnitPriceTextBox.Text
            .Item("Quantity") = QuantityTextBox.Text
            .Item("productname") = ProductNameTextBox1.Text
        End With
 
        Me.TextBox1.Text = Me.NicolaouDBDataSet.Tables("OrderDetails").Compute("SUM([Total])", "").ToString
 
    End Sub

Open in new window

0
 
demoniumzAuthor Commented:
In the "Total" column of table "OrderDetails", set the Expression to "[UnitPrice]*[Quantity]" (without the quotes, of course

what are u mean
0
 
Wayne Taylor (webtubbs)Commented:
In the Solution Explorer, double click 'NicolaouDBDataSet1.xsd' to open the file.
In the OrderDetails table, right-click to the left (in the grey) of the Total column and select "Properties".
Set the Expression property as suggested.
0
 
demoniumzAuthor Commented:
The column mapping from SourceColumn 'Total' failed because the DataColumn 'Total' is a computed column.
0
 
Wayne Taylor (webtubbs)Commented:
When and where do you get that error?

Please, PLEASE, provide more detail. We are not mind readers....
0
 
demoniumzAuthor Commented:
when i  added  in the sourcolum total the  Expresion  i get error The column mapping from SourceColumn 'Total' failed because the DataColumn 'Total' is a computed column.
 here the error go in this line
Me.OrdersDetailsTableAdapter.Fill(Me.NicolaouDBDataSet.OrdersDetails)

0
 
Wayne Taylor (webtubbs)Commented:
I'm sorry, I suggest you delete this question and ask another. I am unable to help further.

Sorry.

Wayne
0
 
demoniumzAuthor Commented:
did  you know from  where i  can download a sample form  ORDER FORM for vb 2005
0
 
demoniumzAuthor Commented:
????????/
0
 
demoniumzAuthor Commented:
sorry man can u help me here when the product add in the datagridview and let said i enter quantity 2 the previous or the first  product change to Quantity  2 can u tell me how to corect?
0
 
demoniumzAuthor Commented:
promemb quantity solved now go to next problem to total:P
0
 
demoniumzAuthor Commented:
Solution Not exactly provider by the Expert BUT helping me with serious problem  is something that i apreciate and every one here in Expert Exchange is understandable.

Bellow is the code i have Now as my form is worked  ok

Public Class Norder



    Private Sub Norder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
        Me.SuppliersTableAdapter.Fill(Me.NicolaouDBDataSet.Suppliers)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NicolaouDBDataSet.Products)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
        Me.OrdersDetailsTableAdapter.Fill(Me.NicolaouDBDataSet.OrdersDetails)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
        Me.SuppliersTableAdapter.Fill(Me.NicolaouDBDataSet.Suppliers)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Orders' table. You can move, or remove it, as needed.
        Me.OrdersTableAdapter.Fill(Me.NicolaouDBDataSet.Orders)

        TotalSum()
    End Sub
    Private Sub OrdersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.OrdersBindingSource.EndEdit()
        Me.OrdersTableAdapter.Update(Me.NicolaouDBDataSet.Orders)

    End Sub


   
    Private Sub Addpr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addpr.Click
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
        Dim orderdetailstable As New DataTable
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = Productidcombobox.SelectedValue
        dr("UnitPrice") = Unitpricetextbox.Text
        dr("Quantity") = QuantityTextBox.Text
        dr("productname") = ProductNameTextBox.Text
        dr("Discount") = 0
        dr("Total records") = 0
        dr("Total") = Convert.ToDecimal(Unitpricetextbox.Text.ToString()) * Convert.ToDecimal(QuantityTextBox.Text.ToString())

        ds.Tables("OrdersDetails").Rows.Add(dr)

        TotalSum()
    End Sub
    Private Sub OrdersDetailsBindingSourceBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.OrdersDetailsBindingSource.EndEdit()
        Me.OrdersDetailsTableAdapter.Update(Me.NicolaouDBDataSet.OrdersDetails)

    End Sub


    Private Sub clearbu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbut.Click

        OrdersDetailsDataGridView.Rows.Remove(OrdersDetailsDataGridView.CurrentRow)

        TotalSum()
    End Sub

    Private Sub TotalSum()
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
            sum += row.Cells(5).Value
        Next
        Me.TextBox1.Text = sum
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearbut.Click
        Me.NicolaouDBDataSet.OrdersDetails.Clear()
    End Sub

    Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
        OrdersBindingSource.MoveNext()
    End Sub

    Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
        OrdersBindingSource.MovePrevious()

    End Sub

    Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
        OrdersBindingSource.MoveLast()

    End Sub

    Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
        OrdersBindingSource.MoveFirst()

    End Sub

    Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
        OrdersBindingSource.AddNew()

    End Sub

    Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
        OrdersBindingSource.RemoveCurrent()

    End Sub
End Class
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 40
  • 21
Tackle projects and never again get stuck behind a technical roadblock.
Join Now