Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Changing the DataGroup on a form programatically

(0) ShareShare
ReportReport
Posted on by

I have a form containing a grid and a combobox: changing the combobox value should ideally change the set of columns visible in the grid.  I'd like to achieve this by defining field groups on the source table, and using the dataGroup property on the grid (having set the AutoDeclaration property to yes), but this appears to have no effect at runtime: is it possible that the only works as a mutator only when creating the form from scratch?

If so, I think that means setting the AutoDeclaration property on every single column, and having the modified method on the combobox set the visible property on each control true/false appropriately for the different combobox values: I've seen this working, so I don't think I'm missing a grid redraw/refresh method because it would also need to be called after setting visibility.

Clearing the user cache hasn't changed the behaviour, so I'm pretty confident the long-winded way is the only way to achieve this, but it would have been neat to use distinct groups on the table.  Guess one could separate out the fields across different tables and enable/disable the joined datasource at runtime?

*This post is locked for comments

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: Changing the DataGroup on a form programatically

    Glad it worked out. Apparently AX lacks some ability in terms of how control properties could be set/changed during run-time, and we have to write workarounds.

  • Community Member Profile Picture
    on at
    RE: Changing the DataGroup on a form programatically

    Having tried both these approaches, it feels like a question of weighing up development time and "neat" code (i.e. doesn't feel too solution-specific) against runtime.  Whilst the development environment in which I'm working may be a little low on processing power compared to the live environment, the difference in performance was sufficient that too many iterations was an issue: making specific sets for different cases worked for me, so thanks for suggesting that halfway house.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Changing the DataGroup on a form programatically

    You can iterate through form controls. Since you are the one adding the controls you could use a custom name for them, and if the looped control name matches the prefix of your choosing, you could delete that control:

    microsoft-dynamics-ax-erp.blogspot.hu/.../iterate-through-all-controls-of-form.html

    It might be possible to loop through just the form groups' contents, I do not have AX in front of me to check.

    But adding/removing them on-the-fly within the group as individual controls is your only option. My script needs some improvements though to support more primitive data types, as the code comment suggests too.

    Alternatively you could maintain the IDs of the run-time controls in a Set, then just enumerate the set when you'd like to remove them, and fill it up again with the new control ids.

  • Community Member Profile Picture
    on at
    RE: Changing the DataGroup on a form programatically

    Thanks Vilmos.  I can see that working insofar as I'm getting new columns added: I need to put some time into clearing away the existing controls (otherwise I just have a really long list of columns added each time the combobox changes), and tweak the display option on date/time controls to only display the date, but that's a great step forward.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Changing the DataGroup on a form programatically

    I have published an article that form datagroups are not being populated runtime, but you could add the controls yourself, have a read:

    www.daxrunbase.com/.../add-ax-formgroupcontrol-runtime

    Based on the selection change of your combo box, you could just repopulate the form group control which you have added as empty with the field group contents of your choice.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans