Hi friends,

Using VB.Net 2005, I have a datagrid to enter purchased items with quantity and purchase price, and calculates the total cost for each row (item). It looks something like this:

RecordID-------ItemID-------Qty------UnitPrice-----------ItemTotal
1 ------------- 1000 ------- 2 --------- 10 ----------------- (20)
2 ------------- 1004 ------- 5 --------- 30 ----------------- (150)
================ etc ====================

The value in ItemTotal column is computed according to data entered in both Qty and Price (immediate computing) but I don't find a property of the column to set this formula.

I tried to use the data grid "Cell Value Changed" event in a way like this:

Dim CurRow As Int16
Dim CurQty As Int16
Dim CurPrice As Single

CurRow = Me.DataGridView.CurrentRow.Index
CurQty = IIf(IsDBNull(Me.DataGridView.Item("Qty", CurRow).Value), 0, Me.DataGridView.Item("Qty", CurRow).Value)
CurPrice = IIf(IsDBNull(Me.DataGridView.Item("UnitPrice", CurRow).Value), 0, Me.DataGridView.Item("UnitPrice", CurRow).Value)
Me.DataGridView.Item("ItemTotal", CurRow).Value = CurQty * CurPrice

First, is this the best way to do what I want?
Second, Using this code, all the steps are going correct, except the last line (in red), which gives an internal error. Each time it executes this line, it resets all variables and calls the procedure again and again infinitely.

Any idea please?

Hi
You can do that
create one function for this calculation
pass to data row values that function for each row

and in cell formating event of data grid
check for that colunm "Total"and call that function if it is true

if you need mero understanding let me know

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.