Returning static values to a datagrid

Posts   
 
    
Posts: 134
Joined: 04-Mar-2005
# Posted on: 28-May-2005 00:47:37   

Is it possible to return a static and/or a derived value to a TypedList?

What I want to do is something like:

select a, b, "a" as staticValue, case(a=1, "Y", "N") as derivedValue
from foo
where...

It doesn't matter whether the SQL is actually executed like that but I'd like a result set that has the extra columns staticValue and derivedValue. Is this possible?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-May-2005 11:44:53   

No, not directly via the fields. You've to add the column to the typedlist after the fetch. For example: add a DataColumn to the TypedList.Columns collection (it's a datatable).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 04-Mar-2005
# Posted on: 28-May-2005 16:53:46   

I've added the column in the varous places that are indicated by ' __LLBLGENPRO_USER_CODE_REGION_START... however I'm unclear how to base my added column/field on anything apart from a database column. Could you give me an example of a static and a dervied column to replace this:

_fields.DefineField(CustomerFieldIndex.Id, Me.AmountOfFields, "DealerType", "", AggregateFunction.None)

DealerType is a derived field based on the values of three other fields.

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-May-2005 15:54:25   

Don't add a DefineField simple_smile . Do: typedList.Columns.Add(new DataColumn(...));

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 04-Mar-2005
# Posted on: 31-May-2005 15:08:15   

Otis wrote:

Don't add a DefineField simple_smile . Do: typedList.Columns.Add(new DataColumn(...));

My second head slap for the morning... I've removed the DefineField and now have things working well if I explicitly reference my derived column/property however the derived value is not accessible to the datagrid (as far as I can tell). I think this has to do with the way the datagrid retrieves the column values but this is where my .NET knowledge runs out. Am I on the right track? Could you give me a pointer or two? I know this is sort of off-topic for LLBL Gen but any assistance is appreciated.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 31-May-2005 20:35:35   

The column should be visible in the grid, as it's a normal datacolumn. You just added a datacolumn to the Columns collection and it doesn't show up? hmm... A datatable is bound using its DataView object, which in turn simply produces property descriptors for all datacolumns in its datatable, so it should turn up.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 04-Mar-2005
# Posted on: 31-May-2005 22:18:17   

Otis wrote:

The column should be visible in the grid, as it's a normal datacolumn. You just added a datacolumn to the Columns collection and it doesn't show up? hmm... A datatable is bound using its DataView object, which in turn simply produces property descriptors for all datacolumns in its datatable, so it should turn up.

The _column _is available however the values in the columns are all false (it's a boolean) until I explicitly reference datatable.columnname at which time (I think) the property is accessed and the derived value calculated. Does this sound right or am I completely off track?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 31-May-2005 22:57:30   

I've never used this feature, but it does sound kind of silly to me though, why calculate the value when it's first accessed?...

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 04-Mar-2005
# Posted on: 20-Jun-2005 17:41:49   

The answer, for those interested, is to add an expression to the column when adding the column to the table.

So

             _columnName = New DataColumn("Name", GetType(System.String), Nothing, MappingType.Element)

becomes

             _columnName = New DataColumn("Name", GetType(System.String), "LastName + ', ' + FirstName", MappingType.Element)

It seems odd to me to add it here but it works and who am I to argue with the way Microsoft does things... confused