Here is m code:
foreach (DataGridViewRow r in dgv01.Rows)
if (r.Cells[0].Value.ToString() == abc)
{
dgv01.Rows.Remove(r);
//dgv01.CurrentCell = dgv01.Rows[0].Cells[0]; - also tried
}
But only some rows are deleted - not all specified !?
Why - foreach - does not mean - foreach ?
Loading

Jignesh TrivediPosted May 25, 2012, 12:57 AM
you can also use RemoveAt method.
try..
for(var i=0;i<=dgv01.Rows.count-1;i++)
{
DataGridViewRow r = dgv01.Rows[i]
if (r.Cells[0].Value.ToString() == abc)
{
dgvEmployee.Rows.RemoveAt(i);
}
}
you can also do one thing remove that row from datasource i.e data table or collection.
Examle if you data set to bind datagrid then
Dataset dataset = dgv01.DataSource as Dataset;
for(var i=0;i<=dataset.Tables["Employees"].Rows.count-1;i++)
hope this will help u.{
DataRow r = dataset.Tables["Employees"].Rows[i]
if (r.Cells[0].ToString() == "abc")
{
dataset.Tables["Employees"].Rows[i].Delete();
}
}
MementoPosted May 25, 2012, 1:16 AM
I just replaced your loop by an reverse loop and - it works:
for (int i = dgv01.Rows.Count - 1; i >= 0; i--)
ThanksAgain!