Change a label dynamically

tompynationtompynation Member Posts: 398
Hi,

Is it possible to change a label his Caption in the OnAfterGetRecord method?

And could we make a textbox invisible, or disabled? Also in the OnAfterGetRecord...

Thx

Answers

  • BeliasBelias Member Posts: 2,998
    report or form?(in each case you can, but you have to work/workaround in different ways)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • SavatageSavatage Member Posts: 7,142
    edited 2008-07-09
    If you explain in more detail what you want to do then we can help more.

    http://savatage99.googlepages.com/ButtonThingy.JPG
    http://savatage99.googlepages.com/ButtonThingy2.JPG

    **Edit Added Button Thingy examples**
  • garakgarak Member Posts: 3,263
    in a form possible, but not in a report.
    What you want to do :?:

    Regards
    Do you make it right, it works too!
  • Cem_KaraerCem_Karaer Member Posts: 281
    The easiest way to simulate a dynamic caption change of a label is to use a textbox control on card forms. The Editable, Focusable and Border properties of the textbox should be set to No. But this is not applicable in list forms. You must apply following to change the caption of a label.

    To change the caption of a label, use the following technics:
    1. Set the CaptionClass property to a variable or a constant
    2. Modify CaptionClassTranslate function of the codeunit 1 so as to process the assigned value of the captionclass.
    3. If you used a variable for the captionclass property, change the value of the variable in code dynamically, but don't forget to call CurrForm.UPDATE and CurrForm.UPDATECONTROLS functions.

    Here is a short example of what I did:

    1. I added following code fragment to the CaptionClassTranslate function
    EXIT(CaptionExpr);
    
    2. I declared a text(80) variable in a list form, say myVariable. And I set CaptionClass property of a textbox in the tablebox to myVariable.
    3. I added two buttons with following code in their OnPush() triggers
    myVariable := 'VALUE1'; //and 'VALUE2' for the other button
    CurrForm.UPDATE;
    CurrForm.UPDATECONTROLS;
    

    When I clicked first button, the caption of the textbox (which is shown as a column in the tablebox) set to 'VALUE1'; and when I clicked the other button it set to 'VALUE2'.

    You can change your algorithm in the CaptionClassTranslate function as you wish.

    Don't forget to close Navision before testing the development because Codeunit 1 is a static codeunit and its initial compiled code, which loaded at the start, will persist unless you quit Navision.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • tompynationtompynation Member Posts: 398
    I've set caption class property of Label to VELD1

    Then in CodeUnit1 i added following code to the CaptionClassTranslate function:


    CASE Language OF
    2067 :
    CASE CaptionExpr OF
    'VELD1' : EXIT('Veld1');
    'VELD2' : EXIT('Veld2');
    END;

    But the text 'Veld1' is not displaying as my label caption ??

    Am i missing something? It's NAV 5.0 SP1
  • tompynationtompynation Member Posts: 398
    I tried the other option with a variable as well, but it isnt working neither...

    I've changed captionclass to a global variable = gv_Text2

    Then in the OnOpenForm i added this code:

    gv_Text2 := 'Testje';
    CurrForm.UPDATE;
    CurrForm.UPDATECONTROLS;

    But nothing happens ](*,)

    When i add the EXIT(CaptionExpr); as first line in the CaptionClassTranslate method of CodeUnit 1

    I get a messagebox popping up when i open the item card asking me if i am sure that i want to rename a record ??
  • tompynationtompynation Member Posts: 398
    It does work, but i had to add the Caption class inside the Table
    not on the form \:D/
  • Cem_KaraerCem_Karaer Member Posts: 281
    Do not put EXIT(CaptionExpr) at the start of the CaptionClassTranslate function, which will ruin all VAT and dimension related captionclass processing!
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • goldeneyegoldeneye Member Posts: 14
    I'm a time-traveller from the year 2018. Me and my colleague are working on this strange artifact called NAV 2009 R2 Classic Client. We were trying to dynamically alter a list form's captions.

    We modified the CaptionClass property which worked on initial load, but were stumped after CurrForm.UPDATE(FALSE) didn't update the captions to the form's current state. However, CurrForm.UPDATECONTROLS did the trick!

    Thank you @Cem_Karaer :smiley:
    aka Vincent Vancalbergh

    "I tried filtering life, but the universe returned an Internal Error"
Sign In or Register to comment.