How to Refresh Column data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Everyone,
I have added a new column to an existing table. This column is to calculate
the total for an Line item. I'm setting as follows:
DS.Tables(0).Columns.Add("Total", System.Type.GetType("System.Double"),
"UnitPrice * Quantity")
I need to know if there is any way that I can refresh this column to force
it to recalculate the value for that line. I'm trying to get it to update
once the user enters a Qty value. Thanks for any info.
Michael
 
Michael said:
Hi Everyone,
I have added a new column to an existing table. This column is to calculate
the total for an Line item. I'm setting as follows:
DS.Tables(0).Columns.Add("Total", System.Type.GetType("System.Double"),
"UnitPrice * Quantity")
I need to know if there is any way that I can refresh this column to force
it to recalculate the value for that line. I'm trying to get it to update
once the user enters a Qty value. Thanks for any info.
Michael

Since a DataTable column can not contain a formula you can not do this
as you are thinking. What you can do is add an event to your Qty column
so that when the user changes the value you write code to update your
new column.

Something like:
addhandler DS.Tables(0).ColumnChanged, Addressof Column_Changed

Private Sub Column_Changed(sender As Object, e As DataColumnChangeEventArgs)
'Update your new column here
End Sub

Hope it helps
Chris
 
Michael,

I don't think it the nicest solution, however when you find nothing better.
(the problem is that the data is normaly pushed in the datatable at the
moment when there is a rowchange)

You can of course as well use styles and than use the event of the
datagridtextbox to let the endcurrentedit push the data in the datatable..

However this is very simple to do.

\\\needs only a datagrid on a form and pasting in this code.
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Quantity", GetType(System.Double))
dt.Columns.add("UnitPrice", GetType(System.Double))
dt.Columns.Add("Total", GetType(System.Double), "UnitPrice *
Quantity")
dt.LoadDataRow(New Object() {2, 4}, True)
DataGrid1.DataSource = ds.Tables(0)
End Sub
Private Sub DataGrid1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
BindingContext(DirectCast(DataGrid1.DataSource,
DataTable)).EndCurrentEdit()
End Sub
///

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top