Solved

Clearing DataGridView C#

Posted on 2009-04-13
4
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

628 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