• Status: Solved
• Priority: Medium
• Security: Public
• Views: 924

# Datagrid view calculations

Hello  i have a datagrid view  iwant to make the calculate  for each row.I  have quantity  and unit price (the logic is to multiply quantity  with the unit price) but i dont know who to write it down to  vb and where.

Also i need to calculate total rows sum
can anyone help me pls
0
demoniumz
• 79
• 38
• 4
• +1
1 Solution

Commented:
How you want that. Do you have to calculate when they check any check box or what?Where you have to show that total amount and Quantity * price?
0

Commented:
Cells(3) in on DataGridView will be the Total, Cells(1) will be the qty and Cells(2) will be the Unit price.

Then you can put a TextBox1 on your form to display the Total from column 3.

jppinto
Dim sum As Decimal = 0
For Each row As DataGridViewRow In DataGridView1.Rows
row.Cells(3).Value = row.Cells(1).Value * row.Cells(2).Value
sum += row.Cells(3).Value
Next
Me.txtBox1.Text = sum
0

Author Commented:
jppinto nice example what about to display it inside the datagrid view in column total
0

Author Commented:
how to make that
0

Commented:
The Total for each row is showned inside the DataGridView. I don't think that is correct to display the total column inside the DataGridView.

jppinto
0

Author Commented:
why you tell these
0

Commented:
It's not "normal" coding putting the column total inside the grid...
0

Author Commented:
oups i mean about row total inside the datagrid view no column total.apologize
0

Author Commented:
example

Order id  Product id   Quantity     unitprice         Total
1              1                 5                 4.20            21.00      One line of the datagridview  give these result

You understan what iwantfirst
0

Author Commented:
anyone to help
0

Commented:
The code that I provided, assumes that you populate your datagridview with 3 columns, Cells(1) for qty, Cells(2) for unit price and Cells(3) for row Total. It will put the row Total on the 3rd column of each row. If you want to put more columns on your datagridview, just change the cell numbers om my code.

jppinto
0

Author Commented:
ok i  try and i provide you the result in the night thnks forhelp
0

Author Commented:
wheere i must the code in the textbox?
0

Author Commented:
where i must add th code
0

Author Commented:
i try it but error.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

My code order form is below
ublic 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.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
Dim sum As Decimal = 0
For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
row.Cells(6).Value = row.Cells(4).Value * row.Cells(5).Value
sum += row.Cells(6).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()

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

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()

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

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
End Class
0

Author Commented:
anyone to chelp me to make these to work please??
0

Commented:
row.Cells(6).Value = row.Cells(4).Value * row.Cells(5).Value

Are these column indexes are correct?
0

Author Commented:
error corect forget that the cell start  to 0 (0 BASED) BUT THE TOTAL OF EACH ROW AND AND COLUM NOT APPEAR yet
0

Commented:
Debug by keeping debug point at for loop or Me.TextBox1.Text = sum and check what is the value in sum.

And Also check whether you are getting right column values
0

Author Commented:
problem resolved at some part but when i add a new product in the datagrid the total  is not appear and the sum not change
.2nd problem  when  a product remove it the sum is not change
3rd add a new  order  the total is not reset to  0
0

Commented:
Keep the whole logic of multiplying and summing to show in text box in seperate function.

When ever you update or remove , call that function so it will update column value and text box total value
0

Author Commented:
can u  help me  to make a function when a product add to   give row total and update the total column
0

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

End Sub

Where ever you are updating/ adding call Total()
0

Author Commented:
for delete  what i must called ?
0

Commented:
same you can call Total()
0

Author Commented:
any site  to provide me information for these type of fuction examples?
0

Commented:
You can search in Google for VB.Net tutorials where you ccan find Defining Functions and Subs etc.
Is that working?
0

Author Commented:
nop very much
0

Author Commented:
i dont understand why when i add new product the total  of the row is not appear  but the previous product before the code enter to caslculate thwe sum is appear
0

Commented:
grid should be refreshed after you add the product
0

Author Commented:
how?
0

Commented:
r u binding data to grid view from designer property?
0

Author Commented:
yes
0

Commented:
0

Author Commented:
not working
0

Commented:
Can you place the whole code here what you had ?
0

Author Commented:
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.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
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()

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

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()

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

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
0

Author Commented:
code is here so?
0

Commented:
you didnt seperate the code part as seprate function Total() right?
0

Commented:
Try using this
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.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.

End Sub

Private Sub OrdersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSaveItem.Click
Me.Validate()
Me.OrdersBindingSource.EndEdit()
OrdersDetailsDataGridView.Refresh()
Total()
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

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()
OrdersDetailsDataGridView.Refresh()
Total()
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

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 Total()
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
End Class
0

Author Commented:
Description                                       Line            column
Error      2      Property access must assign to the property or use its value.      D:\Nicolaou\Nicolaou\Norders.vb      23      9      Nicolaou
Error      3      Property access must assign to the property or use its value.      D:\Nicolaou\Nicolaou\Norders.vb      57      9      Nicolaou
Error      4      'Total' is already declared as 'Friend Dim WithEvents Total As System.Windows.Forms.DataGridViewTextBoxColumn' in this class.      D:\Nicolaou\Nicolaou\Norders.vb      102      17      Nicolaou
0

Author Commented:
TOTAL make  problem  see above the errors
0

Commented:
Rename that total() AS TotalSum() and try it
0

Author Commented:
Input string was not in a correct format.Couldn't store <> in OrderID Column.  Expected type is Int32.

dr("OrderID") = OrderIDTextBox.Text
0

Commented:
dr("OrderID") = Convert.ToInt32(OrderIDTextBox.Text)
0

Author Commented:
working better but tootal row and column not display
0

Author Commented:
can u help
0

Commented:
Is that Total column should only be visible on grid  or does it should go to database?
0

Author Commented:
TOtal column  goes to  database
0

Commented:
Is that total column avlbl in your binding source? If yes then in the Cells, check the correct index. Debug the code, and check what is the index of unit price, quantity and total.
0

Author Commented:
how to check if is available in my binding source?
0

Commented:
Go to binding source properties and look for the column collection
0

Author Commented:
i dont find it
0

Commented:
At the button4_click, just keep a break point and try to debug and say what are the columns in Datagridview Datasource. What is the binding sourse for your datagridview?
0

Author Commented:
ii thinks is beeter to update the aplication  so you cabn help can u>?
0

Commented:
ya sure. The thing is for the datagridview, where you are giving datasourse.Is it in the design properties.If Yes, what is the source name?
0

Author Commented:
and my database can u help me pls i am stack here now a lot of days

i upload it for beter understand i am  new to vb 2005 so  maybe i dont know thing so pls open it a llook orders form
NicolaouDB.mdb
0

Author Commented:
can someone tell me how to clear my rows in the datagrid view i have a button  but is not work
0

Author Commented:
???????
0

Author Commented:
Operator '+' is not defined for type 'Decimal' and type 'DBNull'.

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

what is these can some corect it  or provide me a new calculate code?
0

Commented:
In row.Cells(5).Value, you dont have any value. If you want to clear  datagridview, use datagridview.datasource = nothing
0

Author Commented:
In row.Cells(5).Value, you dont have any value what are u mean
0

Commented:
I made some changes to the code i will post it. But there is some problem in your code which is creating some issues.
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.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersDetails' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.

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()
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

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.OrdersDetailsDataGridView.Refresh()
TotalSum()
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
dr("Discount") = 0
dr("Total records") = 0
dr("Total") = Convert.ToDecimal(UnitPriceTextBox.Text.ToString()) * Convert.ToDecimal(QuantityTextBox.Text.ToString())

TotalSum()

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 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
dr("Discount") = 0
dr("Total records") = 0
dr("Total") = Convert.ToDecimal(UnitPriceTextBox.Text.ToString()) * Convert.ToDecimal(QuantityTextBox.Text.ToString())
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

'    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 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
End Class
0

Author Commented:
what a re u mean  what problems?
0

Commented:
When ever i was trying to insert a new record it was overroding the first row. Can u try the application now?
0

Author Commented:
nop yet  is working for you? all ok or no?
0

Commented:
Total column is working fine and text box is showing correct .But insert is not working fine. Can you check it?
0

Author Commented:
insert is working excelent for me now  i remake the form  also  Quantity is now ok the only problem except  total  i have(havent yet  try your code ) is the clear code  the   datagrid view is clear but the save not update the datagrid view  so the next time i load the form i see again  tghe data as before

OrdersDetailsDataGridView.DataSource = Nothing  cauze the aplication  can u  help me to make a  button to clear all the  fields and save it (using biding navigator  save button)

0

Author Commented:
?????????????
0

Commented:
What are all you want to clear.Do yu want to clear dataset also?
0

Commented:
When you want to clear everything then

Me.NicolaouDBDataSet.OrdersDetails = Nothing
0

Author Commented:
to clear dataset you mean when add new order to clean the datagridview?
0

Author Commented:
Error      1      Property 'OrdersDetails' is 'ReadOnly'.      D:\Nicolaou\Nicolaou\Norder.vb      63      9      Nicolaou

Whattttttt????:) what is these
0

Author Commented:
Me.NicolaouDBDataSet.OrdersDetails = Nothing provide error
0

Commented:
Sorry try this
Me.NicolaouDBDataSet.OrdersDetails.Clear(). When you want to clear the dataset?
0

Author Commented:
Excelent work excelent  programer  :) the problems remain   in some part when a product delete de product is deleted normally but the toal is remain the same
0

Commented:
Call TotalSum() At the delete portion of code after deletion is done
0

Author Commented:
want to clear the dataset when  add a new  order form  (add binding navigator +(plus)  button  to clear the datagrid view
0

Commented:
You mean to say Total in the Textbox remains same? If yes make TextBox.Text = String.Empty
0

Author Commented:
the problems remain   in some part when a product delete de product is deleted normally but the toal is remain the same

Problem resolved

0

Commented:
Is that fine?
0

Author Commented:
absolutely  yea 3  morre small problems: :: clear button clear the form  but the save button not save the changes when close and reload aplication the  data that is cleared before is exist in the datagrid view

And the second problem when a total row and total column is appear like 119 lets say  i want to display as (the symbol of euro ) 119.00

Third   when  add a new order form (push the add button in the binding navigator to clear the form  so i can eddit it again
0

Author Commented:
cfan u help me pls on that or  i  must open  new questions
0

Author Commented:
srikanthreddyn143 are u here?
0

Commented:
For the 2nd Problem use this snippet in load

OrdersDetailsDataGridView.Columns(5).DefaultCellStyle.Format = "\$0.00"
Instead of dollar sign use Euro Sign

For1st prob, after you clear it and save make sure the data is getting into database.

For 3rd prob, When you click on add button, before you call OrdersBindingSource.AddNew()

Make Me.NicolaouDBDataSet.OrdersDetails.Clear()
Textbxtotal.Text = String.Empty
0

Author Commented:
For the 2nd Problem use this snippet in load

OrdersDetailsDataGridView.Columns(5).DefaultCellStyle.Format = "\$0.00"
Instead of dollar sign use Euro Sign
where i must write these?
0

Author Commented:
Textbxtotal.Text = String.Empty (these Textbxtotal is the column total?Textbxtotal.Text = String.Empty
0

Author Commented:
Problem 1 and problem 3 resolved
0

Author Commented:
oups ok in  load wait now to find the Euro symbol
0

Author Commented:
how i can  set it to  total column Textbox1.Text
0

Author Commented:
how i can  set it to  total  Textbox1.Text to  be like these "¬ 0.00"
0

Author Commented:
how i can  set it to  total  Textbox1.Text to  be like these " ¬0.00"?
0

Author Commented:
srikanthreddyn143:.........
0

Author Commented:
The problem now and  the last one that remain is the Comun total (textbox1) is not get value like the row \$0.00 but remain 000 can u help
0

Author Commented:
??????
0

Commented:
sorry i was not at desk.

use this Me.TextBox1.Text = sum.ToString("\$#,###.00")

to Clear text box use this

TextBox1.Text = "\$0.00"

For total column format in gridview you can try this also
OrdersDetailsDataGridView.Columns(5).DefaultCellStyle.Format = "\$#,###.00"

0

Author Commented:
Name sum is not decleare why?
0

Author Commented:
hello are u here?
0

Commented:
Me.TextBox1.Text = sum.ToString("\$#,###.00")
use this in TotalSum().dnt use it in load
0

Author Commented:
where i must use it?
0

Author Commented:
problem  why ehen in the form  lets say there is a product Quantity 8 and amount 1.66 give 8 euro
the real result is 8.30 euro why that ?
0

Author Commented:
Total sum is fixed need to fix amount (above problem)
0

Author Commented:
no one know?
0

Author Commented:
something i  forget to mentioned needed:Iwant when a suplier  clicked Lets say  demoniumz Suplier company "KEO LTD" TO SEE ONLY THE "KEO" PRODUCTS and not all the products

srikanthreddyn143: can u help or anyone else want is welcome

thnks for help apologize
0

Commented:
Look whether Total Column in dataset is Decimal or Integer.Let me check and I will let you know.
0

Author Commented:
ok i wait what about th other prpoblem
0

Author Commented:
before is set to long integer now i  put it as decimal or integer  but nothing change
0

Author Commented:
i dont know  where to see in dataset can u help me can u look?i look in my database access 2003 and is set in long integer but after i  turn to decimal and integer nothing change but chek it maybe i am  wrong
0

Commented:
This thread seems to be (almost) equal to this one: http://www.experts-exchange.com/Microsoft/Development/Visual_Studio_Express/Q_24354173.html where I try to get the information from the OP "demoniumz" to understand what is actually the problem. The code posted in both threads is the same.

@demoniumz: you also requested attention on this thread. Can you try to be clear on what you actually want to do?

> ok i wait what about th other prpoblem

> hello are u here?

same as in that other thread: remember we are all volunteers. Don't push us, because that will only have the reverse effect.
0

Author Commented:
The previous Question is asked in a new question in order to not ask something again here.No one provide that i need so i ask here the expert to help  if he can.The other is understable.
0

Author Commented:
Anyway the problems are  exist if anyone want to help me with  these two small problem i am  here

Thnks srikanthreddyn143
0

Commented:
In Access Database the Total Column datatype is Integer change it to Decimal.

For 2nd Prob
Private Sub SupplierIDComboBox_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupplierIDComboBox.SelectedValueChanged
'Load ProductID Combo Box Based on the supplierID
End Sub
0

Author Commented:
i get the same result is working  for you is give you exactly the amount ? can u  sent me the database fixed Upload it here?
0

Author Commented:
Private Sub SupplierIDComboBox_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupplierIDComboBox.SelectedValueChanged
'Load ProductID Combo Box Based on the supplierID
End Sub

These is comment what is the code?
0

Commented:
I dnt have MS Access in my system. I looke dinto it through VS2008.Pls go to MS Access and change the Datatype of that column.

In the commented part ypu have to filter the data using supplierid like this

NicolaouDBDataSet.Products.Select("SUPPLIERID = '" & SupplierIDComboBox.SelectedValue.ToString() & "'")

it s an example

0

Commented:
I dnt kno much abt Binding sources
0

Commented:
> i get the same result is working  for you is give you exactly the amount ?
> can u  sent me the database fixed Upload it here?

demoniumz, I think you are mixing the question threads again. You didn't send the database here, you send it to me. That is why EE doesn't want cross-thread posts of one question, that causes confusion and problems.

We are here to help, and we are all volunteers, I think I already said that earlier. So we can point you in the direction of how to do something, but we are not going to do the job for you.

About Access, you are around here for quite some time, you should know by now how it works, so please ask that question on the Access zone.

-- Abel --
0

Author Commented:
ok abel ok abel
0

Author Commented:
Excelent thnks for help  freind
0

Author Commented:
srikanthreddyn143: need to help me pls can u ?
0

Commented:
What is the problem left?
0

Author Commented:
ii forget to add discount  to the  datagridview  and in the calculation
0

Author Commented:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24376572.html#a24293762 here is my  problem

srikanthreddyn143   i need help pls in order to finish my aplication
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.

## Featured Post

• 79
• 38
• 4
• +1
Tackle projects and never again get stuck behind a technical roadblock.