10
Answers

How to get complete column values from datagridview?

Ask a question
RD Design

RD Design

9y
803
1
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)