how to empty a DataGridView ???

  • Thread starter Thread starter Chris Peeters
  • Start date Start date
C

Chris Peeters

Hi,

I set up some columns in a DataGridView.
I fill the DataGridView with some records by executing an sql-select
statement .. so far so good

Afterwards I clear the DataGridView using :

((DataView)dataGridView1.DataSource).Table.Clear()

.... all records are deleted indeed BUT the setup of the columns as
well.

meaning that when I refill the DataGridView with some records again will
the order of the columns be like that determined by the sql-select
statement, not the order I set up

How do I just empty the DataGridView by keeping the structure of the
columns intact ?

thanks
Chris
 
Chris,

I would cycle through the rows and call Remove on the DataRowCollection
class to remove the rows.

Hope this helps.
 
Why not use dataGridView1.DataSource.Table.Rows.Clear()?
That will omly clear all rows from the table, and not the table definition

/Lennart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top