Change label color dynamically?

KAdamsInCoKAdamsInCo Member Posts: 28
I know that a field's foreground color can be changed in the OnFormat() section.... how about setting the text color of a label dynamically in code? I would like to read a table of user specified "mandatory fields" and change the label color of those fields on a form to indicate to the user that they are "mandatory". (I've gone through the pain of attempting to actually 'enforce' mandatory fields but without great success and will probably default to having a report that a manager can run to identify records with missing mandatory fields.).

Thanks!

Keaton

:)

Comments

  • garakgarak Member Posts: 3,263
    sorry, but when i know this right (no NAV here at home) a lable doesn't have the OnFormat.
    so what is the solution, if needed:

    1. more labels with other colors and you set the visibility like
    CurrForm.labelRed.visible(Condition);
    CurrForm.labelBlue.visible(not Condition); 
    

    2. you doesn't use labels, u use textboxes instead. So you can change th color ;-)

    regards
    Do you make it right, it works too!
  • SavatageSavatage Member Posts: 7,142
    edited 2008-08-27
    You can create two identical labels but with differentnames
    example/
    DescriptionOK (Text is Black)
    DescriptionNOT (Text is Red)

    Lay them on top of each other then show one or the other depending on your reasons. Say you don't want the desription field to be blank in an item.
    IF "Description" = '' THEN BEGIN
     CurrForm.DescriptionNOT.VISIBLE(TRUE);
     CurrForm.DesciptionOK.VISIBLE(FALSE);
    END ELSE BEGIN
     CurrForm.DescriptionNOT.VISIBLE(FALSE);
     CurrForm.DescriptionOK.VISIBLE(TRUE);
    END;
    

    Untested in real world tho I know This works _ i'm not sure if the colors change instantly with the change of the field or moving to the next record and back. Perhaps a currform.update; is needed somewhere.

    Anyway getting back to the original problem of mandatory fields.
    You could set the initvalue to some default value and change the not blank proprty to yes. So at least they are filled in with something and it can't be removed only changed.

    Another would be on the table (we'll use item for example)
    OnInsert()
    Blocked := True;
    
    so a new item/customer/vendor would default to blocked right off the bat.
    Then on the validate trigger of the Blocked field you could
    Testfield the fields you don't want blank. If any of them are then it will error out and the blocked check will remain. The checkmark will only clear once all the testfields clear. Therefore preventing any item/customer/vendor from being used in any transactions beacuse they are blocked.
  • SavatageSavatage Member Posts: 7,142
    garak faster - but I like the idea of using the textboxes instead of the label. :D

    Here's an old doc with related info
    http://www.geocities.com/navision_attai ... uttons.doc
  • garakgarak Member Posts: 3,263
    jup, faster. you know 386 with TURBO Button :lol:
    Do you make it right, it works too!
Sign In or Register to comment.