chage the datasource on a grid within a form

In Dynamics AX 2009 -

How can I change the datasource of a grid on runtime?

I did :

MyGrid.datasource(“myDataSourcename”);

MyGrid.executeQuery();

// even I did : myDataSource_ds.refresh(); myDataSource_ds.refreshEx(-1); myDataSource.reseach(); but in vain.

What is wrong in my code, and how can I resolve the problem?

Thanks :slight_smile:

TreeNode treeNode;
AOTTableFieldList fieldList;
#AOT
#Properties
;
super();
breakpoint;
treeNode = TreeNode::findNode(#Formspath);

treeNode = treeNode.AOTfindChild(‘Form24’);
treeNode = treeNode.AOTfindChild(‘Designs’);
treeNode = treeNode.AOTfindChild(‘Design’);

treeNode = treeNode.AOTfindChild(’[Grid:Grid]’);
treeNode.AOTsetProperty(#PropertyDatasource,‘SalesTable’);
treeNode = TreeNode::findNode(#Formspath);

treeNode = treeNode.AOTfindChild(‘Form24’);
treeNode.AOTsave();

I don’t want to change the AOT itself (there might be many users).

Beside - I have tried the above, and only when I do : close+open the form, I see the changes.

Thanks :slight_smile: