Combine fields in typed list

Posts   
 
    
Posts: 11
Joined: 02-Aug-2005
# Posted on: 30-Sep-2005 16:15:36   

Hi,

is it possible to combine fields (such as firstname and Lastname) in a typed list?

I saw an answer to a similar problem combining the fields in an entity, but I'd like to do it in a typed list without adding an extra field to the database.

Thanks, Rob.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Sep-2005 16:53:00   

You can do this to any of the generated classes. By manually adding your own code to the generated class.

for example: Add a new string property "fullName"

public virtual System.String FullName
{
    get
    {
        return FirstName + " " + LastName;
    }
}

Please refer to the LLBLGen Pro documentation, and read the following section: "Using the generated code - Adding your own code to the generated classes"

Posts: 11
Joined: 02-Aug-2005
# Posted on: 03-Oct-2005 12:22:09   

Sorry I don't understand. How can I use that code in a typed list?

Rob.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 13:25:40   

FunkyMonkey wrote:

Sorry I don't understand. How can I use that code in a typed list? Rob.

In each typedlist class file, you'll have 2 classes, one for hte typedlist and one for the row. In the Row, you'll find this region: Custom Typed List Row Code

Inside it, you'll find, as stated in the docs, a user code region. Between the two comment lines, you add your code. It's preserved during code generation.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 11
Joined: 02-Aug-2005
# Posted on: 03-Oct-2005 15:09:40   

Should this allow me to use the FullName property as the DisplayMember for a combo box? That is what I'm trying to do.

Or should I be adding a field in the

' __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields ' be sure To Call toReturn.Expand(number of New fields) first. ' __LLBLGENPRO_USER_CODE_REGION_END region?

And if so, how do I go about this? I can't seem to use DefineField as explained in 'Creating dynamic lists' as there is no enumerated field index for the field I am trying to create.

Sorry if I'm not making much sense, I'm just totally stuck on this!!

Thanks again.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 16:11:19   

FunkyMonkey wrote:

Should this allow me to use the FullName property as the DisplayMember for a combo box? That is what I'm trying to do.

Ah. No then you should add a column. TypedLists are derived from datatables, and these produce properties for binding through the DataView which only checks the columns, so no matter which property you add, it won't show up.

Or should I be adding a field in the

' __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields ' be sure To Call toReturn.Expand(number of New fields) first. ' __LLBLGENPRO_USER_CODE_REGION_END region?

Fields are added for dataretrieval. You're adding a column. So to this region: ' __LLBLGENPRO_USER_CODE_REGION_START InitClass ' __LLBLGENPRO_USER_CODE_REGION_END

in InitClass in the typedlist class, you'll add: Dim fullName As New DataColumn("FullName", GetType(String), "Firstname + LastName") fullName.ReadOnly=True this.Columns.Add(fullName)

which effectively adds a computed column to the typedlist. Then, just fill your typed list and it should be showing the column values as well.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 11
Joined: 02-Aug-2005
# Posted on: 03-Oct-2005 16:36:46   

That's brilliant, thank you.