473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

how to empty a DataGridView ???

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 ***
Jul 14 '06 #1
2 32468
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]
- mv*@spam.guard.caspershouse.com

"Chris Peeters" <cm****@yahoo.comwrote in message
news:Ov**************@TK2MSFTNGP04.phx.gbl...
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 ***

Jul 14 '06 #2
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" <cm****@yahoo.comskrev i meddelandet
news:Ov**************@TK2MSFTNGP04.phx.gbl...
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 ***

Jul 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jason_wilkerson | last post by:
I am trying to populate a DataGridView and I get the appropriate number of rows from the XML file, but all of the cells are empty. Can anyone provide any assistance? //Form-designed code: //...
2
by: Greg | last post by:
I have a datagridview that will not always have all its rows populated with data, but they all need to be visible. Currently, the grid is only showing rows with data. Is there a way to override...
2
by: Bryan | last post by:
I have a Windows Application that uses a DataGridView for displaying read-only data. Everything work fine, except when my datasource has no data. Ideally, when there is no data I would like to...
0
by: MKBender | last post by:
Hello everyone, What I'm currently trying to do is allow a user to add a row to my datagridview. I have AllowUserToAddRows set to true. And the empty now does appear at the bottom of my data. ...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
0
by: Dennis Francek | last post by:
Hello I have populated a treeview from my dataset and by clicking in the treeview i want to get the corresponding table shown in a datagridview. Ive managed this by looking at each DataRow and...
0
by: mianghous | last post by:
hi I have a little problem i m using a datagridview on ma aspx page and problem is that its size does not remain same... mean if i fecth 10 records it will show 10 and size will expand of the...
1
by: JustinD30324 | last post by:
Hello. I have a DataGridView that is bound to a DataTable. If the user types in values for all the columns for the first row, then clicks into a column in the second row (empty), and then clicks...
2
by: Lloyd Sheen | last post by:
I am trying to find the event (if there is one) which occurs when a row is added to the DataGridView. The closest I can find is the RowsAdded event which says in documentation: Occurs after a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.