chage the datasource on a grid within a form

This question has suggested answer(s)

In Dynamics AX 2009 -

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

I did :



// 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 :)


All Replies
  • That's kind of odd to change a DS at run time. What exactly do you want to achieve? Why don't you place two grids on a form - each with it's own DS - and make visible one of them at a time?

  • I don't want to place two grid - just need to change its datasource.

    I need a generic solution for above (some fundamental I write for general use).

    Thanks :)

  • Em... AX is not quite a development platform intended to create fancy forms. It's a business application and it has some features that are incompatible with "polymorphic" forms, such as user form setup, access rights setup which requires a form to have all the necessary datasources at a design time, workflows, document management, etc. Besides the AX kernel performs an access rights check for all the tables bound to form data sources only at a form's initialization, so if you try to change a datasource's table after that you'll also have to check the access rights by yourself.

    Anyway if you're looking for a generic solution look at the SysTableBrowser form.

  • I have two datasources on the form (not two grid - the grid is too complicated ...)

    At first time the grid is linked to datasource1, and on runtime I need to link it to datasource2.

    I don't need to build any new columns on runtime.

    I think this has less problems as you have described, since I only need to link to a datasource, that is already on the form.


    (My code is like : myGrid.dataSource("datasource2_name");

     but this doesn't change the datasource).


    Thanks :)

  • What do you mean when you say "to link a grid to a datasource"?

  • The grid has datasource property.

    Whe I do myGrid.dataSource(datasource_name) I suppose the grid should be linked to the datasource, but this doesn't work (the grid on the screen doesn't change at all).

    Thanks :)

  • And what do you think should change if you somehow link a grid with another datasource? Note also that datasources can be linked (for instance inner join'd) and a grid can display fields from several linked datasources while being linked with only one of them via it's "datasource" property. Once again what exactly do you want to achieve by changing the datasource your grid is linked with?

  • Suppose there is a temporary table and you need to link some tables to the temporary table (kind of an on/off filter).

    The temporary table need to be the first in query (you cannot do this otherwise), and the grid should be linked to the temporary table. For that I build a new query based on the original query (not obvious thing at all), but therefore I need to delcare the temporary table datasource as the datasource of the grid, and that's complete my issue. MyGrid.datasource(...) doesn't work,

    (It is for speeding up - the temporary table acts as a filter table, which is the small table is on the top of the query ... A filter table may have records, which I can insert into it fastly by insert_recordset ...).

    , but I think I found a better solution which is having one single datasource (no changes on the grid), and changing the datasource table property. Once it points to the temporary, and once to the general table (also need to make some little fixes on the query behind). Tommorow I'll check that out, and find whether it solves the issue mentioned.


    Thanks :)