Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Clearing DataGridView C#

Posted on 2009-04-13
4
Medium Priority
?
235 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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