Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Open a form on clicking a cell in a grid

(0) ShareShare
ReportReport
Posted on by

Is it possible to open a form that displays related data when I click on a cell in grid ?

For example, if I have a column called 'Expenses' in grid that displays expenses by an employee, then clicking on the cell under 'Expenses' column should open a new form or window that displays the detail breakup of the Expenses value. The grid contains other columns like Employee Name and Employee Location.

One of the problems in above scenario is that there is no cell-click event available for a grid column. There is a mouse down event, but even if I override it for a column, it fires for all other columns as well when I have not overridden mouse down event for these other columns.

*This post is locked for comments

  • Annette Theissen Profile Picture
    Annette Theissen 1,653 on at
    RE: Open a form on clicking a cell in a grid

    Wow, that's really interesting! I will make sure to try it out soon.

    Thanks for the warning!!!

  • RE: Open a form on clicking a cell in a grid

    Hi Annette, I did some investigation and found this.  Everything works exactly as you mentioned i.e. mouse up/down events fire only for a grid column if defined at column level. BUT, if I add a column whose value comes from a 'display' method and not from a data field, then these same events fire for everything in the form.

    In my case I am using a calculated expression in the column in question, and therefore using a 'display' method to supply its value. The only option that works in this case is the global option approach I mentioned.

  • Annette Theissen Profile Picture
    Annette Theissen 1,653 on at
    RE: Open a form on clicking a cell in a grid

    Ah, very good, it really should be like that!

    The debugger might of course interfere with the exact events sent to the form, though it will not fire those events actively.

    I'm also glad that you don't have to use the "global" variable, that's usually a bad sign (even though of course there are many valid reasons to do so, but in this case, it shouldn't be required).

    Have fun!

  • RE: Open a form on clicking a cell in a grid

    Hi Annette,  Now suddenly the mouse up/down are working fine on original grid when defined at column level.  So, I could just use your proposed solution, even though the solution I came up with also works.

    I still don't know what was causing this issue. When this problem occurred, I had debugging turned on, but not sure if that contributed to my problems.

    Appreciate all your help. Thanks.

  • RE: Open a form on clicking a cell in a grid

    Hi Annette, You are right. When I created a new Form with a grid, then what you said was happening i.e. the mouse up mouse down event was happening only for that column in grid for which I wrote the override method.

    So thanks for your pointers.  I will now need to find why in original grid this was not happening.

  • RE: Open a form on clicking a cell in a grid

    Hi Annette, I was able to make this work. I have posted this in my last reply.  I could not find a way of limiting the mouse up or down override method to only one column of a grid. I think AX fires it automatically everytime even though its overridden only at a grid column level but not sure.

    Anyhow, the solution I gave works perfectly with no problems.

    Thanks for all your help.

  • Annette Theissen Profile Picture
    Annette Theissen 1,653 on at
    RE: Open a form on clicking a cell in a grid

    Hi,

    before starting anything else, please find out why your modification to mouseup on only one control seems to be active on ALL controls, otherwise, you will continue chasing ghosts.

    Why do I say that it's important to clarify this?

    • mouseUp is the event to implement such behaviour, this is not only done in AX, but other GUI systems, too.
    • Window or realControl are practically identical
    • Hyperlink is mainly a different way to guide the user.

    If there is no better place that you can find to get started with that, I'd recommend to create a very simple new form with a grid and three controls, only implement the mouseUp method on one control and verify whether the behaviour is as intended, i.e. the form only opens for the one control. Use the mouseUp method as indicated by me above.

    If you're satisfied that it works, find out the differences to the implementation on the form you really want to change. Do this step by step to see what modification breaks the simple form. (Or else, depending on how many modifications you have on your form, you might undo them all / delete from the layer and start again.)

    If you still find that this simplest of all forms doesn't behave as it should, you have constructed a simple form that you can share with the community through an xpo and we can have a look at it.

    Kind regards,

    Annette

  • Verified answer
    RE: Open a form on clicking a cell in a grid

    I was able to implement this requirement FINALLY . 

    The approach I used was to use a global variable that was declared  at the form level class declaration. Such variables are accessible anywhere within the form, even in control override methods. Note that intellisense does not show this global variable, but it is there since you never get an error on saving code that uses this global variable.

    • first go to the form in question and in its class declaration under its Methods, define a global variable called 'cellInFocus' as in code below.
    public class FormRun extends ObjectRun
    {
        str cellInFocus;
    }
    
    • go to non-editable column (  clicking this column cell is supposed to open a form) in Grid > Methods> override Enter.  Add the code below here, which is setting the name of column in focus.  In this case, I am setting the value of global variable 'cellIInFocus' to 'ItemDescription'. The mouse down method will always fire after 'enter' method.
    public void enter()
    {
          super();
          cellInFocus = "ItemDescription";
     }

    • in the Mouse Down override method, add the following code, to check if global variable cellInFocus equals 'ItemDescription'. If it does, then we know we are in the correct column to open a popup form.  BUT make sure to set the global variable 'cellInFocus' to an empty string, so the form does not popup when any other area of the grid  has a mouse down method fire.
    public int mouseDown(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift)
    {
         Args args;
         FormRun formRun;
         int ret;
    
    
        ret = super(_x, _y, _button, _Ctrl, _Shift);
    
    
    
        if(cellInFocus == "ItemDescription")
        {
           cellInFocus = "";//this is very important
           args = new Args("Form1");
    
           formRun = classFactory.formRunClass(args);
           formRun.init();
           formRun.run();
           formRun.wait();
        }
      return ret;
    }

    • Then to give user an impression that the value in this cell is hyperlinked, I went to properties of the column in question and set ForegroundColor to 'HyperLink' and Underline to 'Yes'. This makes the UI more intuitive for end-user since they will try to click on the hyperlinked value, which will fire the override event and cause the form to open.

    NOTE: We can use a similar global variable approach to know which column has focus when using a grid.

  • RE: Open a form on clicking a cell in a grid

    Hi Annette,  I will try the window control, but you also mentioned hyperlinks. You mean adding hyperlinks to the gridform control.  What form is using these hyperlinks?  

  • Annette Theissen Profile Picture
    Annette Theissen 1,653 on at
    RE: Open a form on clicking a cell in a grid

    [quote user="Ivan Kashperuk"]

    No, you can't do that.

    The button outside of the grid is the pattern consistent with the other 3000+ forms in AX.

    Don't invent an unnecessary new pattern, use an existing one

    [/quote]

    Hi Ivan,

    I hope this won't come across as if I wanted to pick a fight ...

    While I'm quite strict about coding practices and code quality myself, I still wouldn't reject such a request and solution in 100% of the cases. The following is why:

    • Standard AX does open forms from grids and gridlike constructs. See the vendTable example above, or hyperlinks in info parts or hyperlinks in non-editable grids.
    • The number of patterns standard AX shows has increased in AX2012 anyhow, and AX is less consistent in form behavior than it used to be. (OK, now it's obvious that I'm still not convinced that the 2012 UX is better than AX2009 UX, even after 4 years :-))
    • Sometimes we just have to give in to a key user, because it will make them accept other things that we really cannot do differently. I honestly just assumed that this was such a case.

    I also want to add one argument against the "mouseUp" solution: I haven't tested how this will appear to a user who doesn't have permissions on the menuItem in question. Could be that they receive an irritating error message - which then means that we'd have to add a security check, too ... which I would've forgotten as well, because I only thought of it now :-)

    As I said, just want to add my 2cents, don't want to start a fight!

    Kind regards,

    Annette

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans