locked
Computed field not showing up in list of available fields in screen designer RRS feed

  • Question

  • Hello,

    I've created the following table structure. Note the FriendlyStartDate which is a computed field.


    Code for that field looks like this:

            partial void FriendlyStartDate_Compute(ref string result)
            {
                if (this.StartDate != null)
                {
                    result = StartDate.ToString("d-MM-yyyy");
                }
                else
                {
                    result = string.Empty;
                }
            }

    Basically, I want to present a user friendlier date than the standard date. Yes, I know I could override the rendering on the client, but that would mean that I would have to provide the entire rendering for all values while all I want to do is change the default formatting on a date.

    Anyway, after making this change, I can't find the new field anywhere in the screen designer.

    Am I wrong in assuming that computed fields should be available in the screen designer just like any other field?

    Friday, November 30, 2012 9:40 AM

Answers

  • Calculated field - not supported in the HTML Client as it was in the silverlight world.  However gry this out:

    1. Open html client screen into the screen designer that you want this calculated field to show up in...

    2. At the top of the screen designer, there is an "Add Data Item..." button, click it and this will bring up the Add Data Item dialog. 

    3. In this dialog, change to "Local Property" and set your "type=string" and give it a name that you want...and click OK

    4.  From the left letf tree view list of the designer (this is where the Added Data Item shows up), Drag and Drop it onto the designer surface where you want that field to show up...

    5. After placing it where you want in the designer surface, select it and in the property window you can click the "Edit PostReder Code" link.  Now here is where you can I believe go ahead and set the field value...

    Hope this helps!


    Robert Schoen (Microsoft Visual Studio LightSwitch Team)

    Friday, November 30, 2012 7:49 PM

All replies

  • For now they are only available in the Silverlight client. In the LS designer at the bottom are buttons to determine the context (client-type(s)/server). It was a bit confusing for me at first.

    And yes, date formatting is being done by us in the preview as pointed out in the render event. I am using moment.js for this.

    Going forwards I don't know if this will change.


    Dave Baker | Xpert360 blog | twitter : @xpert360 Opinions are my own. Please mark as answer if this helps solve your problem.

    Friday, November 30, 2012 7:25 PM
  • Calculated field - not supported in the HTML Client as it was in the silverlight world.  However gry this out:

    1. Open html client screen into the screen designer that you want this calculated field to show up in...

    2. At the top of the screen designer, there is an "Add Data Item..." button, click it and this will bring up the Add Data Item dialog. 

    3. In this dialog, change to "Local Property" and set your "type=string" and give it a name that you want...and click OK

    4.  From the left letf tree view list of the designer (this is where the Added Data Item shows up), Drag and Drop it onto the designer surface where you want that field to show up...

    5. After placing it where you want in the designer surface, select it and in the property window you can click the "Edit PostReder Code" link.  Now here is where you can I believe go ahead and set the field value...

    Hope this helps!


    Robert Schoen (Microsoft Visual Studio LightSwitch Team)

    Friday, November 30, 2012 7:49 PM
  • Is there a way to do this for a collection? I have a collection of A items, and each of those items has another collection of B items inside.

    I want in my Browse screen to show how many B items each A item has in it collection, but I have no idea on how to do this on the HTML client, any tips?

    Regards!


    Vicente Cartas Espinel - MVP XNA/DirectX

    Blog about C# and XNA Development

    Blog about Role Playing Games

    Tuesday, March 12, 2013 1:24 AM
  • Hi Vicente,

    Christopher describes how to show a count for a collection in the following thread:

    http://social.msdn.microsoft.com/Forums/en-US/lightswitchhtml/thread/fa5319fc-7d01-42b5-acfb-ee4ce7c4a77b

    Heinrich

    Wednesday, March 13, 2013 9:02 PM
  • I may not understand it correctly, but I don't want to show a single count, I want to show the count for each item of a collection that is represented in a list (a Browsable screen).

    In the LS Silverlight Client, I would create a calculated property in the entity (e.g.: NumberOfChildren), get the count inside that property and then I could use that property in my grid as any other normal property, so each entity in the grid would show their number of children.

    In the HTML client, calculated properties created in the server do not appear in the client side, so I am at a lost on how I can have a list of entities, and add a new field to all the entities that shows the number of children each entity has.

    Hope it is clearer now (or maybe I didn't understand the post, if that's the case sorry).

    Regards!


    Vicente Cartas Espinel - MVP XNA/DirectX

    Blog about C# and XNA Development

    Blog about Role Playing Games

    Wednesday, March 13, 2013 9:31 PM