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

  • Home
  • SEARCH
  • 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 3310454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:45:44+00:00 2026-05-17T21:45:44+00:00

This doesn’t work. var result = from row in grid.Rows where (string) row.Cells[COLUMN_1].Value ==

  • 0

This doesn’t work.

var result = 
    from row in grid.Rows
    where (string) row.Cells["COLUMN_1"].Value == "Test"
    select row.Cells["COLUMN_2"].Value as int?;

But this does.

var result = 
    from row in grid.Rows.Cast<DataGridViewRow>()
    where (string) row.Cells["COLUMN_1"].Value == "Test"
    select row.Cells["COLUMN_2"].Value as int?;

As far as I can tell, the DataGridViewRowCollection is a collection of DataGridViewRows. So why do I have to cast each member to a DataGridViewRow before I can access its properties?

Does it have anything to do with the fact that DataGridViewRowCollection implements the non-generic IEnumerable but not the generic version IEnumerable<DataGridViewRow>? Or that it apparently uses an ArrayList internally? It’s not causing me any real problems, but I’d like to understand it better.

  • 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-17T21:45:45+00:00Added an answer on May 17, 2026 at 9:45 pm

    Yes, it’s exactly because of the interface it advertises. Almost all the extension methods in LINQ work on IEnumerable<T> rather than IEnumerable. Cast<> is one way of bridging that gap – OfType<> is another.

    However, there’s a simpler way of calling Cast<T> – just explicitly type your range variable:

    var result = 
        from DataGridViewRow row in grid.Rows
        where (string) row.Cells["COLUMN_1"].Value == "Test"
        select row.Cells["COLUMN_2"].Value as int?;
    

    The compiler turns this into exactly the same code as your second sample.

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

Sidebar

Related Questions

Can anybody tell my why this doesn't work in the Android emulator? From the
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
This doesn't work. I've got an exception from SQL databse that column does not
I'm not sure why this doesn't work: scala> case class Loader(n: String, x: String,
This doesn't work: Dim Qry = From RE In DB.Res_Estab Where _ (RE.Estab_Code =
How come this doesn't work (operating on an empty select list <select id=requestTypes></select> $(function()
For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
This doesn't work panel1.layout: layout [ offset: 0x0 yuml-image: image img ] panel2.layout: layout
Why this doesn't work? (For hell's sake!) template<class T> class A { typedef typename

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.