How to mark actual record

jpussler
jpussler Member Posts: 6
Hello,

I thought maybe somebody could help me with my problem. In a form I would like to mark the actual record (where the cursor is placed) with bold letters or in another font color. Is this possible and how can I do this. Any suggestions would be fine.

Thanks

Jochen

Comments

  • Marije_Brummel
    Marije_Brummel Member, Moderators Design Patterns Posts: 4,262
    eeehm. There was a posting about this on MBSOnline. But it is not running at the moment. :?

    I thought Timo Lasser had a solution for this.

    I'll try to remember it...
  • kine
    kine Member Posts: 12,562
    May be something like OnFormat compare primary key of Rec with primary key last accessed record in OnAfterGetCurrRecord and if they are same, use bold font...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Marije_Brummel
    Marije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes it was something like that but with a neat trick for unappliing these changes when going to the next record.
  • garak
    garak Member Posts: 3,263
    Every TextBoxes have the Onformat - Trigger enter here your code.

    Here is an example:
    OBJECT Form 99999 Cust List-example
    {
      OBJECT-PROPERTIES
      {
        Date=16.12.05;
        Time=19:55:14;
        Modified=Yes;
        Version List=NAVW14.00;
      }
      PROPERTIES
      {
        Width=11660;
        Height=6710;
        Editable=No;
        CaptionML=[DEU=Debitoren?bersicht;
                   ENU=Customer List];
        TableBoxID=1;
        SourceTable=Table18;
      }
      CONTROLS
      {
        { 1   ;TableBox     ;220  ;220  ;11220;5500 ;HorzGlue=Both;
                                                     VertGlue=Both }
        { 2   ;TextBox      ;0    ;0    ;1650 ;0    ;ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="No.";
                                                     OnFormat=BEGIN
                                                                IF "No." = '10000' THEN
                                                                  CurrForm."No.".UPDATEFORECOLOR(255);
    
                                                                CurrForm."No.".UPDATEFONTBOLD("No." = '20000');
    
                                                                CurrForm."No.".UPDATESELECTED("No." = '60000');
                                                              END;
                                                               }
        { 3   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=2;
                                                     InColumnHeading=Yes }
        { 4   ;TextBox      ;1640 ;0    ;8441 ;0    ;HorzGlue=Both;
                                                     ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr=Name;
                                                     OnFormat=BEGIN
                                                                IF "No." = '10000' THEN
                                                                  CurrForm.Name.UPDATEFORECOLOR(255);
    
                                                                CurrForm.Name.UPDATEFONTBOLD("No." = '20000');
    
                                                                CurrForm.Name.UPDATESELECTED("No." = '60000');
                                                              END;
                                                               }
        { 5   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=4;
                                                     InColumnHeading=Yes }
        { 14  ;CommandButton;4400 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Default=Yes;
                                                     PushAction=LookupOK;
                                                     InvalidActionAppearance=Hide }
        { 15  ;CommandButton;6820 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Cancel=Yes;
                                                     PushAction=LookupCancel;
                                                     InvalidActionAppearance=Hide }
        { 29  ;CommandButton;9240 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     PushAction=FormHelp }
      }
      CODE
      {
    
        PROCEDURE GetSelectionFilter@2() : Code[80];
        VAR
          Cust@1000 : Record 18;
          FirstCust@1001 : Code[30];
          LastCust@1002 : Code[30];
          SelectionFilter@1003 : Code[250];
          CustCount@1004 : Integer;
          More@1005 : Boolean;
        BEGIN
          CurrForm.SETSELECTIONFILTER(Cust);
          CustCount := Cust.COUNT;
          IF CustCount > 0 THEN BEGIN
            Cust.FIND('-');
            WHILE CustCount > 0 DO BEGIN
              CustCount := CustCount - 1;
              Cust.MARKEDONLY(FALSE);
              FirstCust := Cust."No.";
              LastCust := FirstCust;
              More := (CustCount > 0);
              WHILE More DO
                IF Cust.NEXT = 0 THEN
                  More := FALSE
                ELSE
                  IF NOT Cust.MARK THEN
                    More := FALSE
                  ELSE BEGIN
                    LastCust := Cust."No.";
                    CustCount := CustCount - 1;
                    IF CustCount = 0 THEN
                      More := FALSE;
                  END;
              IF SelectionFilter <> '' THEN
                SelectionFilter := SelectionFilter + '|';
              IF FirstCust = LastCust THEN
                SelectionFilter := SelectionFilter + FirstCust
              ELSE
                SelectionFilter := SelectionFilter + FirstCust + '..' + LastCust;
              IF CustCount > 0 THEN BEGIN
                Cust.MARKEDONLY(TRUE);
                Cust.NEXT;
              END;
            END;
          END;
          EXIT(SelectionFilter);
        END;
    
        PROCEDURE SetSelection@1(VAR Cust@1000 : Record 18);
        BEGIN
          CurrForm.SETSELECTIONFILTER(Cust);
        END;
    
        BEGIN
        END.
      }
    }
    

    Copy the Code into an new, empty text-File. Import the textfile in the (CRONUS DB), compile the new form 99999.

    After them, take a look in the C/AL Code of the both textboxes (enjoy).

    Regards
    Do you make it right, it works too!
  • Marije_Brummel
    Marije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes. this is nice code but not what is meant by highlighting the current record.
  • garak
    garak Member Posts: 3,263
    okay, its nearly the same way

    Regards

    PS: Are you every time online :?: 8-[
    Do you make it right, it works too!
  • Marije_Brummel
    Marije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • garak
    garak Member Posts: 3,263
    My charity :P
    Do you make it right, it works too!
  • Savatage
    Savatage Member Posts: 7,142
    I live here :mrgreen:

    So THAT's how he does it :lol:
  • Timo_Lässer
    Timo_Lässer Member Posts: 481
    Here the solution:
    Form - OnAfterGetCurrRecord()
    CurrentRecord := Rec;
    
    
    Form - OnTimer()  // TimerInterval = 100
    IF CurrForm.ACTIVE THEN
      IF NOT IsEqual(CurrentRecord2,Rec) THEN BEGIN
        CurrForm.UPDATE(FALSE);
        CurrentRecord2 := Rec;
      END;
    
    
    Description - OnFormat(VAR Text : Text[1024];)
    CurrForm.Description.UPDATEFONTBOLD(IsEqual(CurrentRecord,Rec));
    
    
    IsEqual(Rec : Record "YourTableNo";Rec2 : Record "YourTableNo") : Boolean
    EXIT(
      (Rec."Primary Key Field 1" = Rec2."Primary Key Field 1") AND
      (Rec."Primary Key Field 2" = Rec2."Primary Key Field 2") AND
      (Rec."Primary Key Field 3" = Rec2."Primary Key Field 3") AND
      (Rec."Primary Key Field 4" = Rec2."Primary Key Field 4"));
    
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • garak
    garak Member Posts: 3,263
    With an timer its an easy way. But timer - solution are not so good.

    For example an other way to update the form, is to uese the key-events (up, down). Place a menubutton behind the tablebox. make two entries. Give the entries the key events up, down (make there your update).

    When the user will use the mouse, you can use the tablebox triggers.

    Regards
    Do you make it right, it works too!
  • Timo_Lässer
    Timo_Lässer Member Posts: 481
    garak wrote:
    [...]
    For example an other way to update the form, is to uese the key-events (up, down).
    [...]
    When the user will use the mouse, you can use the tablebox triggers.
    [...]
    Have you any example code for that? It sounds interesting!
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • Marije_Brummel
    Marije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Can be done I think, there are some games in the download section that use the up/down arrowkeys.

    You have to think of manualy programming next(1) and next(-1) and error handling... :?

    And do this for every form the user says he likes it. :(

    Maybe it was better to say it cannot be done :mrgreen:
  • garak
    garak Member Posts: 3,263
    @Mark: thats the easiest way. But notice. For the Users we are gods :-)
    And Gods can programming all.

    Regards.
    Do you make it right, it works too!
  • Erwin
    Erwin Member Posts: 14
    Hello,

    I tried this code, but it doesn't work the it expected it to work. The current record is indeed in BOLD, but the previous current record is also left BOLD. This should be turned back to NOT BOLD.
    The problem is that the OnFormat tirgger is only executed for the new current record. Not for the previous one.

    Any suggestions?

    Erwin
  • kine
    kine Member Posts: 12,562
    I have one suggestion, but you will not like it: don't do what you did. Changing how NAV is displaying actual selected line, is not worth the money customer will gave you for that. If you solve one problem, you will have another. Just teach users how it works.

    Question is: what is the main cause that you are trying to do that? Can you solve this in another way? You need to answer these two basic questions...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.