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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:45:50+00:00 2026-05-11T22:45:50+00:00

I have a DataGridView that is bound to a list of objects called BaseChange.

  • 0

I have a DataGridView that is bound to a list of objects called “BaseChange”. The BaseChange objects are made up of 4 properties…

  • ChangeType
  • ChangeStatus
  • ChangeDescription
  • LastChangeDate

The datagridview has columns for all 4 values as well as a 5th (a checkbox column called “colIsSelected”). There is no problem binding the list to the grid and displaying the items.

The problem is that the query that gets the selected items in the grid is giving me an implicit cast error when option strict is enabled.

This is the query…

Dim _changes As List(Of BaseChange)

_changes = (From _row As DataGridViewRow In dgvChanges.Rows() _
            Where Convert.ToBoolean(_row.Cells(NAME_COLUMN_IS_SELECTED).Value) = True _
            Select DirectCast(_row.DataBoundItem, BaseChange)).ToList()

…and it produces the correct results with option strict off. The implicit cast squiggle is on the “_row As DataGridViewRow” code, and the full message is “Implicit conversion from ‘Object’ to ‘System.Windows.Forms.DataGridViewRow’“.

If I exclude the “As DataGridViewRow” from the query, I get a late binding error on the _row.Cells and _row.DataBoundItem and this also fails option strict.

I need this to work with Option Strict enabled, and in VB. Am I missing something here? Anyone have suggestions?

  • 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-11T22:45:51+00:00Added an answer on May 11, 2026 at 10:45 pm
    (From _row As DataGridViewRow In dgvChanges.Rows() 
    

    your type of the _row object has to match the single version of the collection type.

    as in:

        'Assumes Option Strict On and Option Implicit On
        Dim _changes = (From _row In dgvChanges.Rows() _            
               Where Convert.ToBoolean(ctype(_row,DataGridViewRow).Cells(NAME_COLUMN_IS_SELECTED).Value) = True _           
    Select DirectCast(ctype(_row,DataGridViewRow).DataBoundItem, BaseChange)).ToList()
    

    Linq sees your Rows() collection as IEnumerable, so your row is an object. Explanation at the bottom goes into more detail.

    Added:

    Adding Option Infer should simplify this.

    See for more details:

    What is the best way to mix VB.NET's Option Strict and the new Option Infer directives?

    and

    http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/e3ec737a-42f8-4767-a190-78390202a991/

    Explanation:
    I did some more digging as to why it isn’t simpler. RowCollection for a DataGridView implements the older IEnumberable interface which returns objects, while newer collection types Implement the Generic IEnumerable(Of T) Interface, which returns the type directly, removing the need for casting.

    See msdn for implemented interfaces.

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

Sidebar

Related Questions

I have a collection of objects (List) that is bound to a datagridview. How
I have a DataGridView object to which I've bound a list of objects (of
I have a list of objects (of type 'TrackedSet') that is data bound to
I display some objects that have thumbnails in two ways: one in a DataGridView,
I have a DataGridView that I want to query using Linq (C# WinForm). I
How can I have a datagridview that will autogenerate a textbox instead of a
In my application I have a DataGridView control that displays data for the selected
I have a custom DataGridView column that uses an embedded control that pops up
I have a DataGridViewComboBoxColumn in a DataGridView that's based on a lookup table. The
I have a DataGridView control in a winforms app that I'm working on. 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.