How do I delete a row with a specified index in datagridview? So if I want to delete the row with index [2], then how can I do that?
I have tried:
for (int i = 0; i < dg1.Rows.Count; i++)
{
if (i == 2)//if iteration has reached index 2
{
dg1.Row[i].Delete;
}
}
I am using Winforms
You need to use RemoveAt
on the Rows
collection itself:
dg1.Rows.RemoveAt(i);
Use the
dg1.Rows.RemoveAt(i);
and everything will work. I have done this before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With