Displaying Description not ID Question

Displaying Description not ID Question

Old forum URL: forums.lhotka.net/forums/t/1768.aspx


white911 posted on Wednesday, November 15, 2006

I have a Customer Object with an TypeID. However when I display the customer form I want to show the Type Description not the ID, but the binding should be to the TypeID behind the scenes. How is this done?

brucep replied on Wednesday, November 15, 2006

Lots of things you need to answer before you get an answer:

If you answer these questions, you may get more help and suggestions.

--Bruce

white911 replied on Wednesday, November 15, 2006

I want to show it in a ReadOnly Text Box

The Type Is another Root Object but not in the Customer Object where it's only an Integer

The Type cannot be changed.

It does not join to get the description

I have a TypeList which is a NameValueList

brucep replied on Wednesday, November 15, 2006

Excellent. I would say that ajj's suggestion is ideal.

--Bruce

ajj3085 replied on Wednesday, November 15, 2006

If its a read only object it would be acceptable to load the object from a view or stored procedure which fetchs the typename as well.  But if you already have that data in memory, my first suggestion would have you fetching slightly less data.

ajj3085 replied on Wednesday, November 15, 2006

One method would be to add a Type property to the customer, which uses your CustomerType class behind the scenes to translate the Id to a string.  If you don't have a CustomerType (which has a static property List, which is a cached list of types, see the book for an example) class, make one by subclassing Csla.NameValueList.  Your type property getter could then look like this:

public string Type {
    get {
         return CustomerType.List.Value( TypeId );
     }
}

white911 replied on Wednesday, November 15, 2006

Can I do it in the UI or it has to be done in the object?

In other words is the object responsible for retreiving the type description?

Copyright (c) Marimer LLC