Print Page | Close Window

order by in child collection

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=563
Printed Date: 03-Feb-2026 at 4:16pm


Topic: order by in child collection
Posted By: Makani
Subject: order by in child collection
Date Posted: 28-Nov-2007 at 8:44am
I have an object with a child collection.  I have tied the child collection to a grid.  It is not apparent to me how to pass an order by to the hydration of this collection. Do I have to use an Rdb subquery if I want an ordered child collection?
 



Replies:
Posted By: davidklitzke
Date Posted: 28-Nov-2007 at 12:38pm
You can set up your nested grid by using "chained binding" or by using "event handlers".  The advantage of using "chained binding" (as shown in the "Populating a WinForm" tutorial) is that there is absolutely no code to write.  The disadvantage is that you have no control over how the EntityList for the detail grid is populated.  Therefore, you will need to use an Event Handler.
 
The Event Handler that you will need is for the CurrentChanged event on the BindingSource to which your primary grid is bound.  When the CurrentChanged event fires on the BindingSource, just build a new EntityList.  Build the EntityList using an OrderBy clause.  Note that your query will be asking for all detail objects that have a parent id equal to the id of the currently selected parent.
 
 



Print Page | Close Window