I have a DataGridView that is filled with 4 columns and several rows of data. I want to iterate through a DataGridView and get the cell value only from a specific column, since I need this data to be passed to the method.
Here is my code:
foreach (DataGridViewRow row in this.dataGridView2.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value == null || cell.Value.Equals(""))
{
continue;
}
GetQuestions(cell.Value.ToString());
}
}
This seems to go through all the cells, however I need to specify something like:
foreach (DataGridViewRow row in this.dataGridView2.Rows)
{
foreach (DataGridViewCell cell in row.Cells[2])
{
if (cell.Value == null || cell.Value.Equals(""))
{
continue;
}
GetQuestions(cell.Value.ToString());
}
}
source
share