---
title: "How to get the First Column Values of Selected Rows of DataGridView in C#?"  
description: "How to get the First Column Values of Selected Rows of DataGridView in C#?"  
author: "Anonymous User"  
published: 2013-11-14  
updated: 2013-11-14  
canonical: https://www.mindstick.com/forum/1724/how-to-get-the-first-column-values-of-selected-rows-of-datagridview-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get the First Column Values of Selected Rows of DataGridView in C#?

I am using the below [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) to get the ID of columns :

```
DataGridViewSelectedCellCollection DGV =this.dgvSearch.SelectedCells;for (int i = 0; i <= DGV.Count - 1; i++){string ID = Convert.ToString(dgvSearch.CurrentRow.Cells[0].Value);MessageBox.Show(ID); }
```

I [am getting](https://www.mindstick.com/forum/34179/i-am-getting-error-while-assigning-the-data-to-the-array-list) the ID but I want it once foe each column.

How to do it?

## Replies

### Reply by Pravesh Singh

Hi Ankita,\

Use DataGridViewSelectedRowCollection instead of DataGridViewSelectedCellCollection and loop through the no of rows selected. inside the loop just give the same what u have given. replace this.dgvSearch.SelectedCells with this.dgvSearch.SelectedRows..

## update:

```
 DataGridViewSelectedRowCollection DGV=this.dgvSearch.SelectedRows;  foreach(DataGridViewRow row in DGV)  { DataRow myRow =(row.DataBoundItem as DataRowView).Row;  string ID =Convert.ToString(myRow.Cells[0].Value);  MessageBox.Show(ID);
  }
```


---

Original Source: https://www.mindstick.com/forum/1724/how-to-get-the-first-column-values-of-selected-rows-of-datagridview-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
