locked
Modal window picker confusion RRS feed

  • Question

  • I have two tables... a category table and an activity table. I created a 1 to many relationship between the activity table and the category table such that a category can have many activity records but an activity record can have only 1 category. When I created this relationship Lightswitch created a field in the activity table called MastProd (it’s the name of the category table).

    On the “Update Activity Detail” screen I added the field MastProd as a modal window picker and during entry the MWP works exactly as you would expect... it lists all the categories and allows me to pick one.

    That all works fine... however, the category I pick in the MWP is never retained. If I save the update after selecting the category from the MWP and then call the record up again, the MWP is blank and I must select the category again.

    I then added a field to the activity detail table called category and placed code in the MastProd_changed method to move the selected category from the MWP to the new field called Category in the activity table and that works fine but that leaves me with two fields on the screen, one for selecting the category (MWP) and one for retaining the selection (category).

    How can I make one field perform both functions? How do I get the category selected via the MWP field named MastProd to be retained in the field after saving so that the category is displayed in the field the next time I call up the record without the need for selecting it again?   Of course if I do wish to change the category retained in the field named MastProd I would then use the drop-down built into the MWP and select a different category. 

    This seems to be a simple function that I just can’t get to work but oddly enough I have done this many times in other sections of the program and it seems to work fine.  I must be missing something very obvious but I just can’t see it.

    Any help would be greatly appreciated.

    Monday, March 4, 2013 4:43 PM

All replies

  • When you say "I added the field MastProd as a modal window picker", how did you do that? I'm guessing that you used Add Data Item, yes? All you needed to do was drag the MastProd property to the screen control tree, then change its type from ACB (which it will be by default) to MWP.

    If you did add the property using Add Data Item, the reason that the value's not being saved is because a  property added that way won't be bound to your entity, whereas if you drag the property as I described, it will be bound to your entity, so the value will be saved with the entity.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    Tuesday, March 5, 2013 3:33 AM
    Moderator
  • I'm almost certain that I would have dragged the MastProd onto the screen tree but given the regularity with which I have been wrong these days I wouldn't bet the farm.  

    I'll redo it and let you know.

    Thanks

     
    Tuesday, March 5, 2013 12:39 PM
  • @Yann

    It still doesn't work.  I removed the field from the screen and then I dragged the field from the left pane and dropped it on the screen tree.  I selected MWP... verified the Summary Property was correct and ran the program.  I have no trouble selecting the category from the MWP but after Save and then re-open the record, the MWP is blank and must be re-selected.  

    Tuesday, March 5, 2013 1:16 PM
  • Hmm, that's weird. Are you tabbing away from the MWP after you select a category? Or are you selecting a category, then immediately clicking the Save button, with the MWP still having the focus?

    From memory (I don't use MWP's myself), the selection doesn't actually get pushed to the entity until the MWP has lost focus. Again, if I remember correctly, clicking the Save button doesn't seem to count as the MWP losing the focus. But I'm happy to be corrected on both these statements.

    If that's not the cause of the selected category not being saved, I don't know what else it could be. The relationship obviously exists, evidenced by the fact that dragging the property to the control tree adds an ACB, & also that you can change the type to a MWP.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    Tuesday, March 5, 2013 1:30 PM
    Moderator
  • @Yann... additional info.

    The field named CategoryId in the activity table is the field I used to create the relationship to the MastProd table (also a field called CategoryId).  After checking the actual database after update I can see that the data in the CategoryId field matches the category I selected in the MWP but that means I'm back to needing two fields... a MWP to select the category and the actual field that holds the category after update.

    This can't be... I must have something wrong.  Why would Lightswitch create a new field based on the relationship I created between the two tables but not populate that field with the data that is already in the field used to create the relationship?  Makes no sense.  I must be looking at this the wrong way.  

    Tuesday, March 5, 2013 2:16 PM
  • You didn't answer my questions, so I don't know what else to say.

    But something is definitely wrong, you should not need two properties to do what you want.

    If the project is small, & not confidential, you can clean it, then zip it up & email it to me, so I can have a look at the behaviour directly. Or we could screen share via Skype if you prefer.

    Email & Skype: yann at live dot com dot au


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    Tuesday, March 5, 2013 2:21 PM
    Moderator
  • Sorry about the delay... I was called away and couldn't respond.

    I'm assuming the question I didn't answer was about the tab away from the field.  The answer is "yes" I tabbed away from the field.

    Thank you so much for your generous offer to screen share over Skype.  I do have a Skype account but I never used the feature you mentioned so I'd need some instructions.

    I'll catch you on Skype but we are on opposite sides of the world.  I guess I'll be loosing some sleep tonight.  hahaha     

    Thursday, March 7, 2013 4:38 PM