Connecting Tech Pros Worldwide Forums | Help | Site Map

how to empty a DataGridView ???

Chris Peeters
Guest
 
Posts: n/a
#1: Jul 14 '06
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




*** Sent via Developersdex http://www.developersdex.com ***

Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Jul 14 '06

re: how to empty a DataGridView ???


Chris,

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

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Chris Peeters" <cmrchs@yahoo.comwrote in message
news:OvTDva0pGHA.1592@TK2MSFTNGP04.phx.gbl...
Quote:
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
>
>
>
>
*** Sent via Developersdex http://www.developersdex.com ***

Lennart
Guest
 
Posts: n/a
#3: Jul 14 '06

re: how to empty a DataGridView ???


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

/Lennart

"Chris Peeters" <cmrchs@yahoo.comskrev i meddelandet
news:OvTDva0pGHA.1592@TK2MSFTNGP04.phx.gbl...
Quote:
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
>
>
>
>
*** Sent via Developersdex http://www.developersdex.com ***

Closed Thread