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;
}
}
}
foreach
loop to afor
loop or usei.Cells[2].Value
instead. – 41686d6564