web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Best practice for a variable number of checkbox columns in a form grid

(1) ShareShare
ReportReport
Posted on by 86

I’m on a D365 F&O form with a grid bound to a header/line table pair. I need to show one checkbox column per “type” record from a separate setup table, where the setup table is filtered by site, so different sites can have a different number of active types (anywhere from a handful up to 15-20).

Each checkbox needs to:

  • Reflect a per-row, per-type activated/deactivated state stored in a packed string field on the line table

  • Be editable directly in the grid (check/uncheck updates the underlying record)

  • Correctly reflect state when scrolling/selecting rows and after a save

I experimented with adding CheckBox controls to the grid at runtime via addControl/addControlEx, wiring reads/writes through registerOverrideMethod on modified() and the datasource’s active(). The controls render, and writes work correctly, but the checkbox display doesn’t reliably reflect the stored value when navigating between rows, even after forcing element.redraw().

Before I go further down that path: is there a supported way to get a per-row checkbox column whose count is driven by a variable-length setup table, with reliable display binding? Or is the standard guidance still “pick a fixed upper bound on the number of columns, bind each one to its own DataMethod, and show/hide at runtime”?

Any pointers to a working example would be appreciated.

Categories:
  • André Arnaud de Calavon Profile Picture
    308,274 Super User 2026 Season 2 on at

    Hi @CuriousMind,

    Can you tell why the number of columns should be changed per grid row? This is not an intended behavior. If I browse through rows and see the columns continuous changing, I will go mad.

    Or is the variation in the lines based on a “type” in the header? Can you explain the exact requirement and possibly share a mockup?

  • CuriousMind Profile Picture
    86 on at

    Hi @André Arnaud de Cal... , 
    Thanks for the question. To clarify:

    The columns do not change from row to row. At any given time, every row in the grid uses the same set of columns.

    What can change is the selected site. The form includes a site selector, and users can switch sites without closing the form. The grid columns are based on the active "types" configured for the selected site, so the column set must be refreshed whenever the site changes.

    Example

    Site A has three active types: TypeX, TypeY, and TypeZ. The grid displays three checkbox columns.
    Site B has five active types: TypeX, TypeW, TypeV, TypeU, and TypeT. The grid displays five checkbox columns.

    When the user changes the site, the grid should rebuild its columns to match that site's active types. The columns are not dynamic per row; they are dynamic per site selection.

    So the requirement is a grid whose checkbox columns are driven by a site-filtered setup table and are refreshed whenever the selected site changes.

    What I need to implement: checking/unchecking a box must correctly update the backend, and the UI must correctly display what’s stored in the backend always. All the checkbox states for a given line are stored together as one packed string field. e.g. TypeX1TypeY0TypeZ1 so the read side needs to parse that string per type, and the write side needs to update just that type’s digit within it.

    Is there a reliable way to build this?

  • Suggested answer
    Anton Venter Profile Picture
    21,372 Super User 2026 Season 2 on at

    @CuriousMind 

    Why have this elaborate design if the standard UI can handle your requirements? You could use a header details design in the UI by adding a grid for the related data.

     

    Anyway, to answer your question. You could add the related datasource to your form and then dynamically add/hide the fields to the grid as needed as the site is changed. The added field controls can be bound to the datasource fields so when saving, there would be no need to take of that in the code. Check form tutorial_Form_AddControl to get an idea of what I mean.

     

  • Suggested answer
    Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at

    Adding a control isn't enough, you also need to bind it to something related to the grid data source: either a field or an edit method.

     

    If you use fields, you need a table (possibly a temporary one) with the fields prepared upfront by a developer.

     

    An example of code adding controls to a grid and binding them to edit methods can be found in AccDistFormViewProjectExtension.initializingView(). An example of such a method is ProjectAccountingDistribution.editProjectCategoryId(). The problem is that it doesn't tell you which column it's about, therefore you'd likely need a separate method for each type (to identify what belongs to what0 and you'd need to create the method at design-time. So it's not fully dynamic either.

     

    Something similar (not the same) to your requirement is done with the dynamic display of inventory dimensions. For example, you select that you want to see just warehouses and batches and these two fields are added to the grid. But the design is very different to yours. The fields are bound to InventDim table, which is joined to the main data source, and logic at runtime controls which fields are visible.

     

    If I was you, I'd look at the actual business requirement and think about technical designs more suitable to F&U GUI. Maybe they have strong reasons for requesting this UI, but maybe it's just someone's idea, why the actual business problem can be addressed by other solutions too.

     

    Also, your data model doesn't follow the recommended design of relational database. You effectively want to store multiple values related to a record, which is normally done by creating a table with N:1 relation to the main one. There is a reason why already the first normal form says that you shouldn't combine multiple values in a single field. You don't know how long strings (such as TypeX1TypeY0TypeZ1), may appear there, which is a problem for the field design. If you use a table, you can easily have any number of rows. Another problem is that you can't filter by the field, e.g. to find all records that have TypeV enabled. The data is hard to maintain and work with. And so on.

  • Suggested answer
    CU-1234529-002 Profile Picture
    631 on at

    The standard guidance is do not add a variable number of checkbox controls to a standard D365 F&O grid at runtime. Grid controls are designed to bind to fields on the form datasource; dynamically added unbound checkboxes do not reliably maintain a per-row visual state as rows are scrolled, selected, or refreshed.

    The cleanest supported design is to normalize the packed string into a child table:

    MyLineTypeState

    LineRefRecId

    TypeId

    IsActive (NoYes)

    Add it as a datasource joined to the line table, put the checkbox field in the grid, and filter the child datasource by the active types for the selected site. Each checkbox then becomes a real database field on a real row, so editing, display refresh, save, and navigation work through the standard framework.

    If you cannot change the data model, use a fixed upper bound say 20 checkbox columns each with its own edit method on the line datasource, and show/hide the unused columns based on the site setup. Avoid relying on runtime-added controls and active() overrides for grid cell values.

    If this is genuinely a matrix requirement, consider the Table Control instead of a standard grid. It supports dynamic rows/columns and different cell controls, but it is unbound, so you must handle buffering, edit tracking, validation, and persistence manually.
    confiz

    For 15–20 site-driven types, I would strongly prefer option 1: one child record per line/type. It is more maintainable, queryable, and avoids the display-refresh problem entirely.
    Thanks

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 266 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 217

#3
Subra Profile Picture

Subra 164 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans