How to apply filtering to a child table in a parent/child grid

J

johannblake

I have 2 datagrids on a form. One shows the parent records while the
second grid shows the child records whenever a parent record is
selected.

I have a dataset that includes a datarelation between the parent and
child tables. I can then bind the parent grid to the parent table and
the child grid to the datarelation. This will keeps things
synchronized. However, when the child records are displayed, I don't
really want all of the child records shown but a subset. The child
table has a field called LanguageID and only those records should be
shown when the LanguageID is set to a specific value.

The problem is that the LanguageID field is not part of the
datarelation (and apparently cannot be, as this is not possible to do
in the designer). My solution is to somehow create a datarelation
between the parent table and a dataview (that is created on the child
table) rather than a child table, but I am not sure how this is
possible. All of the overriden constructors of the DataRelation class
require a DataColumn. Is it possible to specify the columns of a
dataview instead of the columns of some table? Or is there some other
solution to my problem?

Thanks for your help
Johann Blake
 
B

Bart Mermuys

Hi,

I have 2 datagrids on a form. One shows the parent records while the
second grid shows the child records whenever a parent record is
selected.

I have a dataset that includes a datarelation between the parent and
child tables. I can then bind the parent grid to the parent table and
the child grid to the datarelation. This will keeps things
synchronized. However, when the child records are displayed, I don't
really want all of the child records shown but a subset. The child
table has a field called LanguageID and only those records should be
shown when the LanguageID is set to a specific value.

The problem is that the LanguageID field is not part of the
datarelation (and apparently cannot be, as this is not possible to do
in the designer). My solution is to somehow create a datarelation
between the parent table and a dataview (that is created on the child
table) rather than a child table, but I am not sure how this is
possible. All of the overriden constructors of the DataRelation class
require a DataColumn. Is it possible to specify the columns of a
dataview instead of the columns of some table?
No.

Or is there some other solution to my problem?

You can set a RowFilter to the DataViewSettings of the DataSet's default
DataViewManager. Since you have a relation you must have a DataSet, so:

someDataSet.DefaultViewManager.DataViewSettings["ChildTableName"].RowFilter
= "LanguageID = .. ";

If you set or change the RowFitler after the child grid is bound, then you
have to refresh the parent CurrencyManager :

((CurrencyManager)BindingContext[parentGrid.DataSource,parentGrid.DataMember]).Refresh();


HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top