locked
Custom default screen not shown RRS feed

  • Question

  • Hi,

    I have a List and Detail Screen showing a list of documents coming from a query filtering the complete document set. I created a custom document detail screen that was set as default screen for the document entity. The problem is that when I call the AddAndEditNew() method for document visual collection, the default detail screen is shown instead of the custom detail screen.

    I tried to implement a custom AddAndEditNew() method looking like this:

    partial void documentListAddAndEditNew_Execute()
    {
        document d=this.documents_by_category.AddNew();
        Application.ShowDefaultScreen(d);
    }

    The new document is correctly added to the list, but no screen is shown to edit the identity.

    What's the way to get it work?

    Wednesday, September 7, 2011 10:01 AM

Answers

  • Hi J-D

    with Application.ShowDefaultScreen(d); means that will open default screen for entity d.

    if you want to open custom screen, you use:

     

    this.Application.ShowSearchCustomers()
    


    where SearchCustomers is created screen (in you case detail screen).

    Just type this.Application. and you'll get Show items for your screen in app.

     

    Hope this help

    Spaso Lazarevic


    Wednesday, September 7, 2011 10:15 AM

All replies

  • Hi J-D

    with Application.ShowDefaultScreen(d); means that will open default screen for entity d.

    if you want to open custom screen, you use:

     

    this.Application.ShowSearchCustomers()
    


    where SearchCustomers is created screen (in you case detail screen).

    Just type this.Application. and you'll get Show items for your screen in app.

     

    Hope this help

    Spaso Lazarevic


    Wednesday, September 7, 2011 10:15 AM
  • J-D

    Also, when you call some screen where you set some property to Is Parameter that screen must be called by providing parameter when called from code.

    Best regards

    Spaso Lazarevic

    Wednesday, September 7, 2011 10:25 AM
  • Spaso,

    The custom screen has no "parameter" property. I gave a new try with

     

    partial void documentListAddAndEditNew_Execute()
            {           
                document d = documents_by_category.AddNew();           
                this.Application.ShowdocumentDetail(d.id_proj_doc);
            }

    Now the correct screen is shown, but it's in read only mode! How do I activate the edition mode?

    Thanks for your help!

    Best regards.

    Wednesday, September 7, 2011 11:11 AM
  • Actually,

    Detail screen need to receive Parameter.

    So in you detail screen

    Choose DocumentId and set Is Parameter to true:

    and if you call this screen (with parameter) as

    this.Application.ShowdocumentDetail(d.id_proj_doc);
    you need to get Edit mode.

    Else, if you call DetailScreen without parameter (IsParameter is false) you can't get Edit mode.

    Try this with existing DocumentId, not newly created.

    Hope this help

    Spaso Lazarevic




    Wednesday, September 7, 2011 11:35 AM
  • And also try in debug mode to find what value is for d.id_proj_doc when you call ShowdocumentDetail.

    Is this object saved in entity document.

    Spao Lazarevic

    • Proposed as answer by Spaso Lazarevic Wednesday, September 7, 2011 12:20 PM
    Wednesday, September 7, 2011 11:52 AM
  • You're right, that's the problem! Since d.id_proj_doc is the primary key of document and is automatically attributed by the database, when I call the ShowDocuementDetail, d.id_proj_doc value is still 0. I would have to save the new document to the database to get a valid id, but it's not possible because a lot of fields don't allow null values. How does lightswitch act when the default AddAndEditNew() is called?

    I tried to call ShowdocumentDetail with an id_proj_doc corresponding to another document and you're right, the screen is then in edit mode.

    Wednesday, September 7, 2011 12:19 PM
  • I'm glad that we find what is wrong with your code.

    Best regards

    Spaso Lazrevic

    Wednesday, September 7, 2011 12:22 PM
  • Spaso's answer in this thread could also be helpfull: http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/9580bab2-2e91-4302-a529-cf07f7fe9239

    The user experience is a little bit different with a New Data Screen than with the default application behavior that opens a modal window.

    Wednesday, September 7, 2011 1:33 PM
  • This video has some useful techniques for those who are new to creating add/edit screens:

    How Do I: Create a Screen That Can Both Edit And Add Records In a LightSwitch Application?


    Yann

    (plus ça change, plus c'est la même chose!)

    Wednesday, September 7, 2011 1:45 PM
    Moderator