Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Conditionnally show or hide a checkbox from a grid

(1) ShareShare
ReportReport
Posted on by 17
Hello,
I need to conditionnally hide a checkbox (of type FormCheckBoxControl) that is embedded in a Grid (of type FormGridControl). This might be obvious to you but all of that is in a Form.
The checkb will hide or show based on the value of another fields of the Grid of the associated record.
 
I am looking at something where for each row of the grid if the value of my field is X then the checkbox will be hidden.
This could be done as the grid gets populated or after the fact, by going thru it.
 
The Grid is populated from a Datasource that is a Table.
 
What are the methods that I could use to get to the even and set the visibility.
 
Thanks for the help,
 
  • Suggested answer
    Komi Siabi Profile Picture
    Komi Siabi 12,759 Most Valuable Professional on at
    Conditionnally show or hide a checkbox from a grid
    Salut, 
     
    The value Etat can be OK or KO. The checkbox Forcé can be checked or not if etat is KO (base on what we have on the database).
    However, if the Etat is OK, we want to hide the checkbox (or show it unchecked) despite what the database indicate for the value.
     
    With this requirement, Martin's advice is the best. You can make Forcé editable or not based based on the value of Etat.
     
    You could have a method called updateDesign().
     
     void updateDesign()
        {
            if(Etat.valueStr() == "OK")
            { 
               Forcé.allowEdit(false)
    
            else if(Etat.valueStr() == "KO")
            { 
               Forcé.allowEdit(false)
            }
       }
     call this method the active method of the datasourse like this:
    element.updateDesign()
     
     
    You might as well want control the field Forcé when a user edits Etat to "OK" or "KO". Hence, on the modified method of the field Forcé on the form, call the updateDesign() method.
    element.updateDesign()
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,817 Most Valuable Professional on at
    Conditionnally show or hide a checkbox from a grid
    A checkbox is a type of the column.
     
    Unchecked checkbox is the one that as its value set to No. Therefore if you want to show is unchecked, you want to set the value of the data source field to No, not to hide any control.
  • Community member Profile Picture
    Community member 17 on at
    Conditionnally show or hide a checkbox from a grid
    Thanks for your comments.
    To clarify, this is not the default checkbox that we are trying to hide / show but a custom one.
    We are not trying to hide the column or the cell. But the Checkbox itself. So the columns are not shifted.
    I assume that the allow edit to false will still show the chekcbox checked (event if it is not editable). What we are after if the show it unchecked of not visible at all.
     
     Here is a copy of the form we have.
     
     
    The value Etat can be OK or KO. The checkbox Forcé can be checked or not if etat is KO (base on what we have on the database).
    However, if the Etat is OK, we want to hide the checkbox (or show it unchecked) despite what the database indicate for the value.
     
    I hope that this will clarify my question.
     
    Thanks again.
  • Martin Dráb Profile Picture
    Martin Dráb 230,817 Most Valuable Professional on at
    Conditionnally show or hide a checkbox from a grid
    Hiding the column would lead to weird UX - you would move to another record, the column would disappear and subsequent columns would shift, and the column would be added again (and columns shifted) when moving to yet another record. A better approach will be changing AllowEdit to false.
     
     
  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    Conditionnally show or hide a checkbox from a grid
    Hi,
     
    Check box control will be enabled or disabled only if the user selects some records in the grid.
    Initially when you open the form, check box control will be shown, whenever the user selects any particular record, it will hide based on the X field value.
    For the above to work you need to write the code on DataSource active or selectionChanged method of the form grid DataSource. Same code you need to write on the modified method of the X field.
     
    Thanks,
    Girish S.
     

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans