delete dataGridView row [modified]
-
Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView. I tried following:
for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
{
this->s_dataGridView->Rows->RemoveAt(j);
}and
int j = this->s_dataGridView->RowCount;
while(j<=0)
{
this->s_dataGridView->Rows->RemoveAt(j);
rowCount --;
}it seems like not working. Yes I found My own Solution this is how it works when the entire row collection is needed to delete;
for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
{
this->securityCodedataGridView->Rows->Remove(row);
}modified on Monday, August 23, 2010 11:28 AM
-
Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView. I tried following:
for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
{
this->s_dataGridView->Rows->RemoveAt(j);
}and
int j = this->s_dataGridView->RowCount;
while(j<=0)
{
this->s_dataGridView->Rows->RemoveAt(j);
rowCount --;
}it seems like not working. Yes I found My own Solution this is how it works when the entire row collection is needed to delete;
for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
{
this->securityCodedataGridView->Rows->Remove(row);
}modified on Monday, August 23, 2010 11:28 AM
Explanation:
//wrong code for(int j =0;j<this->s_dataGridView->Rows->Count;j++) { this->s_dataGridView->Rows->RemoveAt(j); } //right code // the rows goes from 0 to count-1 for(int j =0;j<this->s_dataGridView->Rows->Count-1;j++) { this->s_dataGridView->Rows->RemoveAt(j); }
and again
//wrong code int j = this->s_dataGridView->RowCount; while(j<=0) { this->s_dataGridView->Rows->RemoveAt(j); rowCount --; } // right code int j = this->s_dataGridView->RowCount-1; while(j>=0) { this->s_dataGridView->Rows->RemoveAt(j); j--; }
-
Explanation:
//wrong code for(int j =0;j<this->s_dataGridView->Rows->Count;j++) { this->s_dataGridView->Rows->RemoveAt(j); } //right code // the rows goes from 0 to count-1 for(int j =0;j<this->s_dataGridView->Rows->Count-1;j++) { this->s_dataGridView->Rows->RemoveAt(j); }
and again
//wrong code int j = this->s_dataGridView->RowCount; while(j<=0) { this->s_dataGridView->Rows->RemoveAt(j); rowCount --; } // right code int j = this->s_dataGridView->RowCount-1; while(j>=0) { this->s_dataGridView->Rows->RemoveAt(j); j--; }
-
Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView. I tried following:
for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
{
this->s_dataGridView->Rows->RemoveAt(j);
}and
int j = this->s_dataGridView->RowCount;
while(j<=0)
{
this->s_dataGridView->Rows->RemoveAt(j);
rowCount --;
}it seems like not working. Yes I found My own Solution this is how it works when the entire row collection is needed to delete;
for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
{
this->securityCodedataGridView->Rows->Remove(row);
}modified on Monday, August 23, 2010 11:28 AM
the logical approach:
while(RowCount!=0) Rows.RemoveAt(0);
the smart approach:
Rows.Clear();
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.