RD Design

RD Design

  • NA
  • 25
  • 25.8k

How to get complete column values from datagridview?

Feb 2 2015 3:50 AM
Hi,
 I have a datagridview with 2 columns. Like below one

 Heading1 Heading 2
 BMW 2014
 Jaguar 2005
 Honda 2012

I need to  get cell values (2014,2005,2012) of "Heading 2" column in to array.Have tried this way but not really success

 foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.ColumnIndex == 1)
{
MessageBox.Show(cell.Value.ToString());
Application.Exit();
}
}
}
 How can I achieve this?
Thanks

Answers (10)