I am using WPF datagrid. Can I retrieve rows from datagrid using Linq.
Something like :
List<People> people = from products in datagrid1 select products.ToList<People>();
I think no right? It will be great if Linq support datagrid.
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suspect the problem you’re running into is that
ItemsSourceis weakly typed as justIEnumerable– whereas most of LINQ to Objects works onIEnumerable<T>. You can use theCast<T>()method to create a sequence which will cast each item where necessary. Try this:Note that whenever you see a que ry expression of the form
from x in source select xyou should consider just usingsource– query expressions shouldn’t be used blindly; work out what each one means, and then determine whether it’s the most appropriate way of expressing what you need.If you actually want a bigger query, you may not want to go via a
List<People>at all. For example:(Consider changing your
Peopletype toPersonby the way, unless it really does represent a collection of people – in which case you should probably give it a name which reflects what the collection really means.)