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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:16:12+00:00 2026-06-04T20:16:12+00:00

I have a datagridview in my Winforms Application. The user can click anywhere on

  • 0

I have a datagridview in my Winforms Application.
The user can click anywhere on the datagridview
And then click a button to perform an action on that datarow
However, in order to do this I need to recover the ID from that row
Now bearing in mind the user probably hasnt clicked the ID column
So SelectedCell.Value is no use to me here

I have tried the following code

DataGridViewRow row = dataIPs.SelectedRows[0];
DataGridViewCell cell = row.Cells[0];
string value = cell.Value.ToString();

But this produces an Out Of Bounds error.

How can I obtain the value from a specific column of the datagridview regardless of which column the user actually selects.

ANSWER

The code that worked for me in the end was as follows:

DataGridViewRow row = dataIPs.CurrentCell.OwningRow;
string value = row.Cells["IPID"].Value.ToString();
  • 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-04T20:16:15+00:00Added an answer on June 4, 2026 at 8:16 pm

    You appear to be trying to access the SelectedRows collection when no row has been selected.

    The default selection mode for the DataGridView is CellSelect and in this mode when you click on a cell no row is selected.

    You need to either change the selection mode or get the desired row some other way.

    • You can change the selection mode to FullRowSelect which can be done in the designer or in code:

      dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
      
    • Or you can access the selected cell and the row from that:

      DataGridViewRow row = dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex];
      

      Or like this:

      DataGridViewRow row = dataGridView1.CurrentCell.OwningRow;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms DataGridView in my application. When the user selects a row
I have a datagridview in a c# .net WinForms application that captures order detail
I have a WinForms application that contains a Dataset ds and a DataGridView dgv.
I have a winforms application that I added a DataGridView bound to a subsonic
In a VB.NET Winforms application, I have a form that contains both a datagridview
i am working on a DataGridView in C# 3.5, in winforms application. I have
I have a winforms datagridview that seems to always have at least one row
I have a DataGridView in a Winforms app that has about 1000 rows (unbound)
I have a column Name Quote Price in a DataGridView winforms control. I can
I have a Winforms app that has a DataGridView that is databound at runtime.

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.