Link to home
Start Free TrialLog in
Avatar of tora111
tora111

asked on

Clear datagridview

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

Thanks
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi tora111,

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

hope this helps a bit
bruintje
Avatar of tora111
tora111

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Me.DataGridView1.Rows.Clear() 'Delete all rows in the datagridview1
'or
Me.DataGridView1.Columns.Clear() 'Delelte all rows and columns in the datagridview1
Avatar of tora111

ASKER

Thanks bruintje .
I know this is probably old but wouldn't just clearing the datasource be better?
DataGridView1.DataSource = null;