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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:58:47+00:00 2026-06-14T14:58:47+00:00

I have a WinForms application with a DataGridView , which DataSource is a DataTable

  • 0

I have a WinForms application with a DataGridView, which DataSource is a DataTable (filled from SQL Server) which has a column of xxx. The following code raises the exception of

ArgumentException was unhandled. Column named xxx cannot be found.

foreach (DataGridViewRow row in Rows)
{
    if (object.Equals(row.Cells["xxx"].Value, 123))
}

Is it possible to get the cell values by column name?

  • 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-14T14:58:48+00:00Added an answer on June 14, 2026 at 2:58 pm

    DataGridViewColumn objects have a Name (shown only in the forms designer) and a HeaderText (shown in the GUI at the top of the column) property. The indexer in your example uses the column’s Name property, so since you say that isn’t working I assume you’re really trying to use the column’s header.

    There isn’t anything built in that does what you want, but it’s easy enough to add. I’d use an extension method to make it easy to use:

    public static class DataGridHelper
    {
        public static object GetCellValueFromColumnHeader(this DataGridViewCellCollection CellCollection, string HeaderText)
        {
            return CellCollection.Cast<DataGridViewCell>().First(c => c.OwningColumn.HeaderText == HeaderText).Value;            
        }
    }
    

    And then in your code:

    foreach (DataGridViewRow row in Rows)
    {
        if (object.Equals(row.Cells.GetCellValueFromColumnHeader("xxx"), 123))
        {
            // ...
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a WinForms application that uses SQL server to store its data. To
i have a winforms application and i want to export data from the datagridview
I have a WinForms application with DataGridView control. My control has five columns (say
I have a WinForms application with a DataGridView control and a column of DataGridViewButtonCell
i am working on a DataGridView in C# 3.5, in winforms application. I have
I have a DataGridView in a Winforms application containing a collection of items. Each
I have following code for 3 DataGridView Controls in my VB.NET winform application. How
I have a Winforms DataGridView in my application. When the user selects a row
I have a Winforms application, which hosts two PDF Viewers (Unmanaged C++) in its
I have a winforms application that has one tabcontrol with 2 pages. On both

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.