How to loop through FormBuildDataSource-Fields

Hi all,
i want to set a larger number of fields read only (in one DataSource on my form). I know that i can set the whole DataSource read only (FormBuildDataSource.AllowEdit(false)), but i need that only for some fields.

Is there a way to loop throug the fields of a datasource and set them read only?

Thanks in advance,
Frank

Hi,

You can simply set your grid allowEdit property to no

Regards,

Thomas

I answered to fast, you can add your code in a test: for example in an init() method in the formDataSource : if (yourTest) FormBuildDataSource.AllowEdit(false);

Hi,
thanks for the answer, but setting the grid to read only did not solve my problem. In fat, i have to set all fields on the DataSource except one…

And the Information is displayed in one grid as well as on another tab… So i found this a little error-prone to set each control ro/rw (e.g. if we add fields in the future to the datasource…)

Frank

you can write the code in Active method of the data souce of perticuler form as shown below

if (salesLine.SalesType == SalesType::ItemReq)

{

salesLine_ds.object(fieldnum(SalesLine,TaxServiceCodeId)).allowEdit (false);

}

so that first it will check your condition and if it is satisfying the condition it wont allow to edit the fileds in the grid.

hope it may helps you…

Hi,
thanks a lot, but the problem is: How can i iterate through the fields of a datasource?

Because i don’t want to set the 20 fields of my DataSource RO only to keep one field RW. I think this is a little error-prone e.g. if we add fields in the future to the datasource…

Greets,
Frank

Hi, If you need it dynamically, u have to write code. If not, set allowedit property to “No” in table or datasource of your form as per the need. Code datasource_ds.object(fieldnum(tablenum, fieldname)).allowedit(false) for all the fields except your field. If you feel you have more fields in the table, make the design group allowedit false. Regards, Kuppusamy S

Hi,

Hi, If you need it dynamically, u have to write code
That was my intention - to write code to loop through the fields of a datasource. If it is not possible, it is ok (i will then follow the “(FormBuildDataSource.AllowEdit(false))”-way for 30 columns). But i just was wondering, if there is a way to do a loop :).

Greets,
Frank

Hi,

Hi, If you need it dynamically, u have to write code
That was my intention - to write code to loop through the fields of a datasource. If it is not possible, it is ok (i will then follow the “(FormBuildDataSource.AllowEdit(false))”-way for 30 columns). But i just was wondering, if there is a way to do a loop :).

Greets,
Frank

Hello,

I wrote an example with a Table named Table7, In this example, field2 would be the field that you want to keep editable

public void init()

{

DictTable dictTable;

DictField dictField;

int i;

super();

dictTable = new DictTable(tableNum(Table7));

for(i = 1; i<= dictTable.fieldCnt(); i++)

{

dictField = new DictField(tableNum(Table7), dictTable.fieldCnt2Id(i));

//If you try to modify the property of a system field you will get an error

if(!dictField.isSystem() && dictField.id() != fieldNum(Table7, field2))

{

Table7_ds.object(dictField.id()).allowEdit(false);

}

}

}

Best Regards,

Manuel Esquivel

Thats it :). Thanks a lot!

Greets,
Frank

That’s it :slight_smile:

Thanks a lot!

Greetings,
Frank