Solved

Clearing DataGridView C#

Posted on 2009-04-13
4
222 Views
Last Modified: 2012-05-06
Hi, I was wondering how can I clear a DataGridView.
As in clearing all the contents inside, like Clear();
0
Comment
Question by:csharp_learner
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 250 total points
ID: 24128742
Doable by :
int rowCount = DataGridView1.RowCount - 1;
for (int i = 0; i < rowCount; i++)
{
DataGridView1.Rows.Remove(DataGridView1.CurrentRow);
}
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24128748
[or]
if (this.dataGridView1.DataSource != null)
{
     this.dataGridView1.DataSource = null;
}
else
{
    this.dataGridView1.Rows.Clear();
}
0
 

Author Closing Comment

by:csharp_learner
ID: 31569436
Thanks for your solution
0
 

Author Comment

by:csharp_learner
ID: 24128778
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question