Solved

# Datagrid view  calculations

Posted on 2009-04-21
866 Views
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
Question by:demoniumz

LVL 11

Expert Comment

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

LVL 33

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

how to make that
0

LVL 33

Expert Comment

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

LVL 1

Author Comment

why you tell these
0

LVL 33

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

anyone to help
0

LVL 33

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

wheere i must the code in the textbox?
0

LVL 1

Author Comment

where i must add th code
0

LVL 1

Author Comment

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

LVL 1

Author Comment

anyone to chelp me to make these to work please??
0

LVL 11

Expert Comment

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

Are these column indexes are correct?
0

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

for delete  what i must called ?
0

LVL 11

Expert Comment

same you can call Total()
0

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

nop very much
0

LVL 1

Author Comment

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

LVL 11

Expert Comment

grid should be refreshed after you add the product
0

LVL 1

Author Comment

how?
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

yes
0

LVL 11

Expert Comment

0

LVL 1

Author Comment

not working
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

code is here so?
0

LVL 11

Expert Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

TOTAL make  problem  see above the errors
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

dr("OrderID") = OrderIDTextBox.Text
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

working better but tootal row and column not display
0

LVL 1

Author Comment

can u help
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

TOtal column  goes to  database
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

i dont find it
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

???????
0

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Accepted Solution

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

LVL 1

Author Comment

what a re u mean  what problems?
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

?????????????
0

LVL 11

Expert Comment

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

LVL 11

Expert Comment

When you want to clear everything then

Me.NicolaouDBDataSet.OrdersDetails = Nothing
0

LVL 1

Author Comment

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

LVL 1

Author Comment

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

Whattttttt????:) what is these
0

LVL 1

Author Comment

Me.NicolaouDBDataSet.OrdersDetails = Nothing provide error
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

Is that fine?
0

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

srikanthreddyn143 are u here?
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

Problem 1 and problem 3 resolved
0

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

srikanthreddyn143:.........
0

LVL 1

Author Comment

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

LVL 1

Author Comment

??????
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

Name sum is not decleare why?
0

LVL 1

Author Comment

hello are u here?
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

where i must use it?
0

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

no one know?
0

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 1

Author Comment

ok i wait what about th other prpoblem
0

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 39

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

Thnks srikanthreddyn143
0

LVL 11

Expert Comment

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

LVL 1

Author Comment

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

LVL 1

Author Comment

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

LVL 11

Expert Comment

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

LVL 11

Expert Comment

I dnt kno much abt Binding sources
0

LVL 39

Expert Comment

> 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

LVL 1

Author Comment

ok abel ok abel
0

LVL 1

Author Closing Comment

Excelent thnks for help  freind
0

LVL 1

Author Comment

srikanthreddyn143: need to help me pls can u ?
0

LVL 11

Expert Comment

What is the problem left?
0

LVL 1

Author Comment

ii forget to add discount  to the  datagridview  and in the calculation
0

LVL 1

Author Comment

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

## Featured Post

### Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library aâ€¦
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that aâ€¦
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This lâ€¦