adding calculated field to a typedList

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 05-Mar-2008 01:09:35   

version 1.0.2005.1 final (self-servicing) VS2005 asp.net 2.0


hiya,

Is it possible to create a calculated field in the designer?

eg, I have the following fields: 1) dateOfBirth 2) dateOfdeath

I need to calculate the age at death...(dateOfdeath-dateOfBirth) ..in years

This has to be contained within a typedList because I have to bind it to a grid.

Any advice appreciated.

Many thanks,

yogi

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 05-Mar-2008 06:36:19   

Since a TypedList is a DataTable, you can add a calculated column to it at the point it is retrieved.

See the Expression property on DataColumn for a full list of what you can do in a calculated column.

Cheers Simon

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 05-Mar-2008 22:34:09   

hiya Simon,

Unfortunately my scenario's a bit more complicated.

As you know, I have the following fields:

1) dateOfBirth 2) dateOfdeath

The calculated column can either be: 1) an integer 2) "N/A" (if the dog isn't dead yet.)

I have tried the dataColum expression:

DataColumn dCol = new DataColumn("ageAtDeath");
dCol.Expression = "DateOfDeath.Year - DateOfBirth.Year";

I get an error because the expression doesn't recognise the "year"

Cannot find column [DateOfDeath.Year].

So, I'm stumped at the first hurdle.

Any ideas?

Many thanks,

yogi.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 05-Mar-2008 22:34:10   

hiya Simon,

Unfortunately my scenario's a bit more complicated.

As you know, I have the following fields:

1) dateOfBirth 2) dateOfdeath

The calculated column can either be: 1) an integer 2) "N/A" (if the dog isn't dead yet.)

I have tried the dataColum expression:

DataColumn dCol = new DataColumn("ageAtDeath");
dCol.Expression = "DateOfDeath.Year - DateOfBirth.Year";

I get an error because the expression doesn't recognise the "year"

Cannot find column [DateOfDeath.Year].

So, I'm stumped at the first hurdle.

Any ideas?

Many thanks,

yogi.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Mar-2008 23:53:23   

You should use DBFunctionCall. Unfourtunely you are using v1.x. So you have to:

  • Retrieve the typedLlist
  • Add a column "YearsOfLife" manually
  • Iterate the DataTable and set the "YearsOfLife" value to the difference between the two other columns.
David Elizondo | LLBLGen Support Team