[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11901
  • Last Modified:

Clear datagridview

How can I clear a datagridview, delete all rows and columns ?

Thanks
0
tora111
Asked:
tora111
1 Solution
 
bruintjeCommented:
Hi tora111,

assuming you mean to erase the data not the structure you can try
DataGridView1.Rows.Clear()

hope this helps a bit
bruintje
0
 
tora111Author Commented:
bruintje, no both data and structure.

Because I created the structure at run-time by user-input, so I need to re-create the grid if user change input.

0
 
bruintjeCommented:
this will delete the rows and columns

        Dim rw As DataGridViewRow, cl As DataGridViewColumn
        For Each rw In DataGridView1.Rows
            DataGridView1.Rows.Remove(rw)
        Next
        For Each cl In DataGridView1.Columns
            DataGridView1.Columns.Remove(cl)
        Next
0
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.

 
maidinhtaiCommented:
Me.DataGridView1.Rows.Clear() 'Delete all rows in the datagridview1
'or
Me.DataGridView1.Columns.Clear() 'Delelte all rows and columns in the datagridview1
0
 
tora111Author Commented:
Thanks bruintje .
0
 
txghia58Commented:
I know this is probably old but wouldn't just clearing the datasource be better?
DataGridView1.DataSource = null;
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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