I am trying to loop through two columns in a DataGridView and add them into a coordinate as below
foreach (DataGridView row in dataGridView1.Rows)
{
double x = Convert.ToDouble(row["X"]);
double y = Convert.ToDouble(row["Y"]);
Coordinate c = new Coordinate(x, y);
Point p = new Point(c);
IFeature currentFeature = fs.AddFeature(p);
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
currentFeature.DataRow[i] = row[i];
}
}
but I am encountring with following error:
Cannot apply indexing with [] to an expression of type
‘System.Windows.Forms.DataGridViewRow’
Can you please let me know why this is happening?
Regards,
It’s fairly simple –
DataGridViewRowclass does not expose an indexer. You need to access cells via itsCellscollection.row.Cells[i]should probably do the trick: