First of all, let me re-post your code in a readable way and throw away unused variables:
[FormDataSourceEventHandler(formDataSourceStr(WHSLocation, WMSLocation), FormDataSourceEventType::Initialized)]
public static void whsLocation_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun element = sender.formRun();
FormCheckBoxControl disableLicensPlate = element.design(0).controlName(“WHSLocation_DisableLicensPlate”);
WSHLocationProfile wshLocationProfile;
while select wshLocationProfile
{
if (wshLocationProfile.LocType == ‘VPG’)
{
disableLicensPlate.allowEdit(true);
}
else
{
disableLicensPlate.allowEdit(false);
}
}
}
The cricual problem is that you’re trying to do the work at a wrong place. You try to set editability for the same field several times and you hope that it’ll set different values for different records, but it’s not how it works. You’re just overwritting the same value.
You need to run the logic for the currently selected record. Use CoC extension of active() methodthe form data source, or handle Activated event.
Also, you should set editability of the data source field, not just an individual control. You can do it in this way:
var dsField = formDataSource.object(fieldNum(WHSLocation, DisableLicensPlate));
dsField.allowEdit(wshLocationProfile.LocType == ‘VPG’);
This also solves the problem that you hard-coded in control name as string. If it was a valid scenario for referring to a control name, you should have used formControlStr() instead of a string.
It’s a pity to see that this question has already been answered in another forum. Please avoid duplication and if you do it anyway, keep the information in sync. You don’t want to waste time of people that are willing to help you, do you?