Filtering radio button items out

maqk® by MolviDSLR Khan | 3:15 PM

Radio buttons or option buttons are used to provide user with single option selectable interface.

In AX, the usual practice is to bind a base enum with the enum type property of the radio button so that it renders all elements of the base enum as available options. When making general data forms, all base enum fields of a table render as radio button on the forms.

This is all normal and known. What I want to share in this post is a specific scenario with me and can happen with any one else as well.

Take a look at the Gender base enum.

When adding a worker, or a person in DirPerson, you specify the gender of the person which is this field 'Gender' in the AOT. Now it has the two obvious Male and Female items with a "Not so required" Unknown as well.

Ironically, the 'Unknow' option has no label defined as well. This results in a UI rendered as follows.

This yields to a common problem statement, "We may require to load specific values of a base enum in the responsible UI control (drop down / radio button)". In my case, I want to get rid of this extra "No label" option which has no significance in my simple requirement.

I searched on the internet and nothing was up to the exact mark. Further smart searching revealed this very very useful link . What the link asks you is to AutoDeckare your control, override form's run method, and there, use the control's methods to get your work done :). The code is shared as follows;

public void run()
   radioCode.delete(''); //This line removes the option whose text is equal to ''

And my form loads only Male and Female genders. Thats all I want. I will attempt this solution on drop down as well and will update the results here.

One other way to achieve this is leave the binding method and add custom items in the radio button.

Add custom items in Radio button control

I was unaware of the possibility of adding / removing custom items in a radio button list control until today. A There are 3 properties providing interface to add custom items as follows;

  1. Items - number of custom items to add in the radio button
  2. Item - the 1 based index of the current item you are working at the design time
  3. Text - the text of the item currently being edited to display

Binded radio button controls have the first two properties disabled. If you drop a new radio button list on the form or remove the enum type property, these 2 properties will enable.

You can add as many custom items you want. The question rises, "How to tackle custom items in code".

Handling custom items of radio button in code

Well this is not difficult either. The following code demonstrates how you gonna do it.

Happy coding.


Dedicated ASP.NET Developers said...

Yeah, throughout reading I was thinking that “How to tackle custom items in code”, but when I scroll down you already did the answer of my question. Keep it up!

Offshore Software Development Company

Post a Comment