Filter Master Table based on Child Criteria

R

Rick

I posted a previous message similar to this, but I think that the
presentation wasn't complete.

Thanks to all who tried to decypher the mess. Hopefully this message
will be more understandable.

I have a need to Filter a master DataView (easily) through a
DataRelation and from a child DataView.

For instance, using a Typed DataSet based upon the Northwind Tables
Orders and [Order Details] with a DataRelation
(OrdersOrderDetailsRelation) setup between the two (Orders = Parent /
OrderDetails = Child)

If we populate each of the DataTables (Orders and OrderDetails) with
the full contents of each database table, the DataTables (Orders and
OrderDetails) will in fact contain all the applicable data.

ComponentManager.Instance.Orders.PopulateOrders(_ordersData);
ComponentManager.Instance.OrderDetails.PopulateOrderDetails(_ordersData);

Now, if I use the DefaultView of the DataSet's OrderDetails DataTable
to set the RowFilter = ProductId = 5, and then look at the
DefaultView's count it will show 10 DataRowViews, exactly as I would
expect.

_ordersData.OrderDetails.DefaultView.Count will return 10.

I need to access all of the Orders records associated with these 10
records. I had hoped that I could create another DataView based upon
the Orders DataTable - but with respect to this
OrderDetails.DefaultView.RowFilter, possibly by the
OrdersOrderDetailsRelation.

Something like:
_ordersData.Orders.DefaultView.RowFilter =
"Orders.OrdersOrderDetailsRelation.ProductId=5"

OR

_ordersData.OrderDetails.DefaultView.DataViewManager.CreateDataView(_ordersData.Orders);
// Shouldn't this work? Creating a DataView from the Filtered
DataView.DataViewManager?

Best regards,

Rick
 
W

W.G. Ryan - MVP

Rick: If I'm understanding you correctly, I think the solution is create a
view for the parent table and then depending on the row selected in the
child, filter accordingly. This won't make for a very nice bind situation if
you're using a datarelation and binding to it b/c it's circular - the child
records depend on the parent and the datarelation forces the filtering. So
if you bind, it's not going to work. But you can get values from one and
use them to set the other using Select and setting rowfilters.
 
C

Cor Ligthert [MVP]

Rick,

Please keep the message to the original messages.
This is confusing for those who answers, because they don't know the
previous answers and makes rereading of a message for those who search on it
almost impossible.

I have placed an answer there.

Cor
 
R

Rick

Not Binding.

This is being used in a service which has no visual elements. I need a
single and complete DataView I can base upon another 'related' DataView
on another table in the DataSet related with a DataRelation.

-Rick

W.G. Ryan - MVP said:
Rick: If I'm understanding you correctly, I think the solution is create a
view for the parent table and then depending on the row selected in the
child, filter accordingly. This won't make for a very nice bind situation if
you're using a datarelation and binding to it b/c it's circular - the child
records depend on the parent and the datarelation forces the filtering. So
if you bind, it's not going to work. But you can get values from one and
use them to set the other using Select and setting rowfilters.
Rick said:
I posted a previous message similar to this, but I think that the
presentation wasn't complete.

Thanks to all who tried to decypher the mess. Hopefully this message
will be more understandable.

I have a need to Filter a master DataView (easily) through a
DataRelation and from a child DataView.

For instance, using a Typed DataSet based upon the Northwind Tables
Orders and [Order Details] with a DataRelation
(OrdersOrderDetailsRelation) setup between the two (Orders = Parent /
OrderDetails = Child)

If we populate each of the DataTables (Orders and OrderDetails) with
the full contents of each database table, the DataTables (Orders and
OrderDetails) will in fact contain all the applicable data.

ComponentManager.Instance.Orders.PopulateOrders(_ordersData);
ComponentManager.Instance.OrderDetails.PopulateOrderDetails(_ordersData);

Now, if I use the DefaultView of the DataSet's OrderDetails DataTable
to set the RowFilter = ProductId = 5, and then look at the
DefaultView's count it will show 10 DataRowViews, exactly as I would
expect.

_ordersData.OrderDetails.DefaultView.Count will return 10.

I need to access all of the Orders records associated with these 10
records. I had hoped that I could create another DataView based upon
the Orders DataTable - but with respect to this
OrderDetails.DefaultView.RowFilter, possibly by the
OrdersOrderDetailsRelation.

Something like:
_ordersData.Orders.DefaultView.RowFilter =
"Orders.OrdersOrderDetailsRelation.ProductId=5"

OR

_ordersData.OrderDetails.DefaultView.DataViewManager.CreateDataView(_ordersData.Orders);
// Shouldn't this work? Creating a DataView from the Filtered
DataView.DataViewManager?

Best regards,

Rick
 

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

Similar Threads

Data Relation 3

Top