• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Clearing DataGridView C#

Hi, I was wondering how can I clear a DataGridView.
As in clearing all the contents inside, like Clear();
0
csharp_learner
Asked:
csharp_learner
  • 2
  • 2
1 Solution
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
Doable by :
int rowCount = DataGridView1.RowCount - 1;
for (int i = 0; i < rowCount; i++)
{
DataGridView1.Rows.Remove(DataGridView1.CurrentRow);
}
0
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
[or]
if (this.dataGridView1.DataSource != null)
{
     this.dataGridView1.DataSource = null;
}
else
{
    this.dataGridView1.Rows.Clear();
}
0
 
csharp_learnerAuthor Commented:
Thanks for your solution
0
 
csharp_learnerAuthor Commented:
Thanks I got it working by using u're first comment.
            int rowCount = AlarmState.RowCount;
            for (int i = 0; i < rowCount; i++)
            {
                AlarmState.Rows.Remove(AlarmState.CurrentRow);
            }
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now