Solved

Clearing DataGridView C#

Posted on 2009-04-13
4
219 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now