Home > DeveloperSection > Forums > How to get the First Column Values of Selected Rows of DataGridView in C#?
Ankita Pandey
Ankita Pandey

Total Post:183

Posted on    November-14-2013 12:51 AM

 C# C# 

 1 Reply(s)
 7059  View(s)
Rate this:

I am using the below code 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);



I am getting the ID but I want it once foe each column.

How to do it?

Pravesh Singh

Total Post:412

Posted on    November-14-2013 1:25 AM

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..


 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);



Don't want to miss updates? Please click the below button!

Follow MindStick