Solved

WPF Master detail grids using LINQ

Posted on 2013-11-15
7
482 Views
Last Modified: 2016-02-10
Hi guys,

What is the easiest way to achieve my goal? Should I have 2 linq queries run when the program is launched and save the results in a public list and then assign a list to each of the grids? Then have a selected row change event acting as a filter to the child's list?

Hope that makes sense?

Thanks,
Dean.

p.s I should mention that these grids will be used to add, remove and edit data.
0
Comment
Question by:deanlee17
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39652591
What if I just said, "Yes"...would that suffice?
0
 

Author Comment

by:deanlee17
ID: 39653193
Hi TheLearnedOne,

haha you could just say "Yes", is this the way you would done it?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39653355
If you are a cat lover, then I apologize for the statement, "there are many ways to skin a cat".  I assume that you are using ObservableCollection, and that you are binding to the grids dynamically in code.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:deanlee17
ID: 39655694
haha I don't like cats, but I wouldn't skin one. Either way i'm not offended.

This is how I am binding....

private void LoadEnquiryHeader()
        {
            using (var context = new AscentEntities())
            {
                grdEnquiryHeader.ItemsSource = context.Qte_Header;
            }
        }

        private void LoadEnquiryFooter()
        {
            using (var EnqFooter = new AscentEntities())
            {

                var EnqFooterVar = (from d in EnqFooter.Qte_Lines where d.LinesAstuteRef == Instance_EnquiryCustomer.AstuteRef select d).ToList();

                grdEnquiryLines.ItemsSource = EnqFooterVar;

            }
        }

Open in new window

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39656278
I prefer Lambda expressions to LINQ queries in most cases:

var EnqFooterVar = EnqFooter.Qte_Lines
    .Where(lines => lines.LinesAstuteRef == Instance_EnquiryCustomer.AstuteRef)
    .ToList();

Open in new window

0
 

Author Comment

by:deanlee17
ID: 39656286
Do they run any faster? Or just personal preference?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39656590
LINQ queries compile into Lambda expressions, so it is personal preference.  I just feel that they are a cleaner way of approaching the same thing.  This is contrary to what others believe, but I don't mind being different.

Query Syntax and Method Syntax in LINQ (C#)
http://msdn.microsoft.com/en-us/library/vstudio/bb397947.aspx

Query syntax and method syntax are semantically identical, but many people find query syntax simpler and easier to read. Some queries must be expressed as method calls. For example, you must use a method call to express a query that retrieves the number of elements that match a specified condition. You also must use a method call for a query that retrieves the element that has the maximum value in a source sequence. The reference documentation for the standard query operators in the System.Linq namespace generally uses method syntax. Therefore, even when getting started writing LINQ queries, it is useful to be familiar with how to use method syntax in queries and in query expressions themselves.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now