Question

I'm using LINQtoSQL to bring data for a DevExpress XtraGrid or a Infragistics UltraWinGrid and show a parent row with a [+] sign so that I could click and see the details (similar to a 2 level tree). I've been sucessful before using a DataRelation for my DataSource and then binding it just did it automatically. How can I achieve this using LINQ?

Example I've used in VB.NET for DataTables in a ADO.NET DataSource:

Dim rel As DataRelation = New DataRelation("Allocation",
        dsAllocation.Tables("tblParent").Columns("AllocKey"),
        dsAllocation.Tables("tblChild").Columns("AllocKey"), True)

This link is the best info I have reasearched, but looking for a more dynamic way of doing it. http://documentation.devexpress.com/#WindowsForms/CustomDocument5495

Thank you.

Was it helpful?

Solution

In general, you can use something that implements IList<X> as the DataSource. If X has a IList<Y> inside it, it'll display in the way you want. So as long as your LINQ query returns a list of X where each X contains a list of Y, it'll work.

Note: Since IList doesn't support notifications so if you want your grid to automatically update when adding/removing from the lists of X and Y, you'll want to use something that implements IBindingList.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top