المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Datagridview delete problem



C# Programming
06-04-2009, 10:41 AM
hi,

here's the layout:
- datagridview with 5 columns, last column is CheckBox Column.

the purpose :
- by pressing a button = deleting each row that has a marked CheckBox

the current algorithem :

if (dataGridView1.RowCount > 0)
{
for (int k = 0; k < dataGridView1.RowCount; k++)
{

if ((bool)dataGridView1.Rows[k].Cells[5].Value)
{
dataGridView1.Rows.RemoveAt(k);
}
}
}

the problem :

after the first deletion, the

"(bool)dataGridView1.Rows[k].Cells[5].Value"
throws this excption :
Object reference not set to an instance of an object.


anybody ???

THANKS http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

Have Fun
Never forget it