Click to See Complete Forum and Search --> : Calculated columns in datagrids


Philip Halton
08-22-2003, 05:51 AM
I am having problems with calculated columns in a datagrid.

I can add a calculated column to a dataset using:

DataSet11.Order_Details.Columns.Add("TotalPrice")
DataSet11.Order_Details.Columns("TotalPrice").Expression = &_
"unitprice * quantity"

and this gives me a calculated column in the datagrid.

However, this only calculates when the user leaves the row, by tabbing through
the column. I want the TotalPrice column to always show the correct total.

I tried using the following, but that just gives me a "readonly exception"
on that column. I don't know what else to try.

Private Sub UpdateLineTotal()
If IsDBNull(DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, &_
2) = False And IsDBNull(DataGrid1.Item(DataGrid1.CurrentCell. &_ RowNumber,
3)) = False Then
DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 5) = &_
CDbl(DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 2)) * CDbl &_(DataGrid1.Item(DataGrid1.CurrentCell.RowNumber,
3))
End If
End Sub