Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:40:40+00:00 2026-06-11T21:40:40+00:00

I am using WPF datagrid. Can I retrieve rows from datagrid using Linq. Something

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:40:41+00:00Added an answer on June 11, 2026 at 9:40 pm

    I suspect the problem you’re running into is that ItemsSource is weakly typed as just IEnumerable – whereas most of LINQ to Objects works on IEnumerable<T>. You can use the Cast<T>() method to create a sequence which will cast each item where necessary. Try this:

    List<People> people = datagrid1.ItemsSource.Cast<People>().ToList();
    

    Note that whenever you see a que ry expression of the form from x in source select x you should consider just using source – 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:

    // Note the explicit typing of the range variable, which corresponds to a Cast
    // call in the query translation.
    var query = from People person in datagrid1.ItemsSource
                where person.Age > 50
                select person.Name;
    

    (Consider changing your People type to Person by 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.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using buildin WPF DataGrid in .net 4. I can set the background of
I'm using the WPF DataGrid control to show some details and a select button,
We're using the WPF DataGrid from the WPF Toolkit and are employing MVVM. I'm
I'm using the WPF toolkit datagrid, and I'd like to set the background color
I'm using a the WPF datagrid from the Microsoft CodePlex project. I have a
When using WPF databinding, I obviously can't do something along the lines of MyCollection
I am using the WPF DataGrid component from the .NET 4 framework, it is
I'm using the WPF DataGrid, and I'd like to know if there is any
I have a WPF DataGrid with some data. You can add rows through a
I am using the WPF Datagrid from Codeplex. I am able to style the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.