Reputation: 15061
I have a DataGridView and I want to change the value in cells of selected rows to the value selected in a drop-down box. It is always the cells in the 3rd column.
My code is:
private void updateSelected_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow i in dataGridView1.SelectedRows)
{
dataGridView1[2, i].Value = Combo.Text;
}
this.BindingContext[dataGridView1.DataSource].EndCurrentEdit();
}
However, I am getting the following error:
CS1503 Argument 2: cannot convert from 'System.Windows.Forms.DataGridViewRow' to 'int'
I have it working to update ALL rows:
private void updateExcel_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
if (!RowIsEmpty(i))
{
dataGridView1[2, i].Value = Combo.Text;
}
}
}
Upvotes: 0
Views: 677
Reputation: 3455
i
is a DataGridViewRow
not a row-number:
foreach (DataGridViewRow i in dataGridView1.SelectedRows)
{
i.Cells[2].Value = Combo.Text;
}
Upvotes: 1