Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to expand tree view by default when page open in navision?

Posted on by Microsoft Employee

Hi All,

I have a page with show as tree property True. But when i run the page by default it was displayed in Collapse mode but i want to in expand.

i have done some R&D i found that below code 

IF (ISCLEAR(WshShell)) THEN BEGIN
CREATE(WshShell, FALSE, TRUE);
END;
WshShell.SendKeys('+{F10}E{ENTER}');
// menu key + E + Enter
CLEAR(WshShell);

But it is with the automation not working for my NAV 2013 R2. my page type is listpart. any other alternative way for the default expand in tree view.

Please let me know.

Thank You

--

Ramesh

*This post is locked for comments

  • Suggested answer
    Da Neal Profile Picture
    Da Neal 45 on at
    RE: How to expand tree view by default when page open in navision?

    There is one way to open all tree nodes programmatically. 

    For example (NAV 2015) in Page 634 you need make this changes:

    1. Add global dot net variables (Must be RunOnClient=Yes)

    CurrForm System.Windows.Forms.Form.'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    ContextMenuStrip System.Windows.Forms.ContextMenuStrip.'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    BusinessGrid Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid.'Microsoft.Dynamics.Framework.UI.WinForms.Controls, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
    ArrayControls System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    (to add BusinessGrid copy Microsoft.Dynamics.Framework.UI.WinForms.Controls.dll to addins path, it is need only to add variable to page)

    2. Add control (i name it PageReady) addin Microsoft.Dynamics.Nav.Client.PageReady;PublicKeyToken=31bf3856ad364e35 to page. It is need to get event when window form genereted.

    3. In PageReady::AddInReady() write code like this

    //Local Variables

    FormID Code 40
    RepeaterID Code 40
    String DotNet System.String.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Application DotNet System.Windows.Forms.Application.'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    FormCollection DotNet System.Windows.Forms.FormCollection.'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    //Code

    FormID := String.Format('{0:X8}',634); //634 is Page ID
    RepeaterID := String.Format('{0:X4}',1); //1 is Repeater control ID
    
    FormCollection := Application.OpenForms;
    CurrForm := FormCollection.Item(FormCollection.Count-1);
    
    RepeaterID := COPYSTR(CurrForm.Name,1,15) + RepeaterID + '-0008-' + COPYSTR(CurrForm.Name,26);
    
    ArrayControls := CurrForm.Controls.Find(RepeaterID, TRUE);
    IF ArrayControls.Length = 0 THEN EXIT;
    
    BusinessGrid := ArrayControls.GetValue(0);
    
    ContextMenuStrip := BusinessGrid.DataGrid.Columns.Item(0).HeaderCell.ContextMenuStrip;
    ContextMenuStrip.Items.Item(ContextMenuStrip.Items.IndexOfKey('{8173ED7E-096D-486f-AF68-873E8DE41170}')).PerformClick ;

    Here is objects with some control feature :)

    /cfs-file/__key/communityserver-discussions-components-files/34/P634_2D00_NAV2017.txt

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: How to expand tree view by default when page open in navision?

    Add the code on the OnAfterGetRecord but add a condition to execute it only on the last record. Get the COUNT in the open page and when it matches with the count execute your code.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to expand tree view by default when page open in navision?

    Hi Suresh,

    presently i am handling through action only, but i want to expand all node by default when i run page. example 634 page need to expand all accounts.

    can you suggest me, what should i do for that?

    Thank you

    Ramesh

    --

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: How to expand tree view by default when page open in navision?

    Ramesh,

    If you add an action on the page and add the above code is it working ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to expand tree view by default when page open in navision?

    Hi,

    above send key was worked  on active application.

    Name DataType Subtype Length

    WindowShell DotNet System.Windows.Forms.SendKeys.'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    WindowShell.Send('^+{Q}');

    but i want to work this when loading a page. any one suggest the solution to resolve.

    Thank you

    Ramesh

    --

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to expand tree view by default when page open in navision?

    Hi,

    I have checked manually cntrl+shift+Q is worked for collage and expand.

    I found keystrokes for cntrl as ^ ,shift +,{Q},

    So totally my send key is '^+{Q}'.

    Is above key I am passing is correct or do I need to change any thing.

    Please suggest me.

    Thanks you

    Ramesh.

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: How to expand tree view by default when page open in navision?

    See there's only two things that need to be taken care of.

    1. SendKey should be correct if you are not passing it correct you wont get any Error but it will not work.

    2. Trigger should be correct, OnOpen Trigger should work I believe, Possiblly you can try on some other triggers.

    Make sure SendKey is correct, Check in some different short program, make confirm then go for triggers.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to expand tree view by default when page open in navision?

    Hi,

    i have Written in Subform OnOpen trigger only, not on main page.

    any other possibility for this?

    Thank you

    Ramesh

    --

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: How to expand tree view by default when page open in navision?

    It will obviously not work from OnOpen Trigger because its the Trigger of the main page not subform. You need to write on SubForm OnOpen  trigger and then it needs to be called from the main Page.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to expand tree view by default when page open in navision?

    Hi,

    I have a below page line like as sales subform.

    Expandcollapse.PNG

    And when page is loaded it need to be default expand how should i do. i found some sendkey code as below


    IF (ISCLEAR(WshShell)) THEN BEGIN
    CREATE(WshShell,FALSE,TRUE);
    END;
    WshShell.SendKeys('^+{Q}');
    // menu key + E + Enter
    CLEAR(WshShell);

    manually Cntrl+Shift+Q is working for line hierarchy but when i written this code in OnOpenpage trigger not working.


    IF "Is Parent" THEN
      WindowShell.Send('^+{Q}'); //^+{Q}

    ^+{Q} := Cntrl+Shift+Q (this is manually working)

    And also above code is also not working in OnAftergetrecord trigger.

    In which trigger i can place this code. even i have placed in Element name that is parent node onValidateTrigger but still not working. 

    Please any one suggest me how to achieve. or any alternative way to achieve this situation.

    Thank You

    Ramesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans