Creating a complex expression for a Typed Dataset element

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

How can I create a property or function for a typed datasets column?
By this I need to add a new column (element) to the table or override an
existing column.
For instance I have an Invoice table that needs to have a Status property.
This status property has to read the other elements in the table to
determine what the status is and return a string.
I know that I can enter this in the expression fields, but as the
expressions become more complex this becomes unmanageable.
 
Andrew,
When my "expression" becomes too complex for a DataColumn.Expression I use
the DataTable.ColumnChanged event to use VB.NET code to calculate the
expression.

Something like (unchecked):

Private Sub Table_ColumnChange(...)
If e.Column.ColumnName <> "Column1" _
AndAlso e.Column.ColumnName <> "Column2" _
AndAlso e.Column.ColumnName <> "Column3" Then

If e.Row.IsNull("Column1") Then Exit Sub
If e.Row.IsNull("Column2") Then Exit Sub
If e.Row.IsNull("Column3") Then Exit Sub

Dim value1 As DateTime = CDate(e.Row.IsNull("Column1"))
Dim value2 As DateTime = CDate(e.Row.IsNull("Column2"))
Dim value3 As TimeSpan = DirectCast(e.Row.IsNull("Column3"),
TimeSpan)

Dim value4 As TimeSpan

value4 = value2.Subtract(value1).Add(value3)

e.Row("Column4") = value4

End If
End Sub

Hope this helps
Jay
 
Back
Top