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 4041732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:55:02+00:00 2026-05-20T12:55:02+00:00

I have the following code, which does work: var dataSource = (from p in

  • 0

I have the following code, which does work:

var dataSource = (from p in dv.ToTable().AsEnumerable() where filter(p) select p).AsDataView();

filter is a Func<DataRow, bool>
dv is a DataView
dataSource is being used as a DataSource for a DataGrid.

Anyhow, it strikes me as a bit ugly that I am calling ToTable, AsEnumerable, and AsDataView, so I was wondering if there is a way to reduce the number of calls.

Is this as simple as I can make it?

Edit: The DataGrid has pagination, and I make use of the dataSource to determine the total number of entries. I’m not especially worried about the efficiency of this; dv only has a few thousand items and the table is being maintained in memory.

  • 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-05-20T12:55:02+00:00Added an answer on May 20, 2026 at 12:55 pm

    Well for one thing, I’d say that using a query expression is somewhat clumsy here. Your code is equivalent to:

    var dataSource = dv.ToTable()
                       .AsEnumerable()
                       .Where(filter)
                       .AsDataView();
    

    which I would say is clearer.

    Another alternative would be:

    var dataSource = dv.Cast<DataRowView>()
                       .Select(rowView => rowView.Row)
                       .Where(filter)
                       .ToList();
    

    This avoids building a DataTable, so may well be more efficient too (it’ll just stream the DataRowViews from the view and select their underlying DataRows) but builds a List<DataRow> at the end. On the other hand, it’s now not acting on the view itself, really – because it’s just selecting the underlying rows. This may or may not do what you need, depending on what your view is doing.

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

Sidebar

Related Questions

I have the following JQuery code which does similar functionality like Stackoverflow where the
I have the following JavaScript code: Link In which the function makewindows does not
I have the following code, which will not work. The javascript gives no errors
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code which works just fine when the method is POST,
I have the following code which works fine. However, I only want to return
Okay so I have the following Code which appends a string to another in
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have the following code, which splits up a Vector into a string vector

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.