Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > how to empty a DataGridView ???
 

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 will the order of the columns be like that determined by the sql-select statement

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

thanks
Chris

Chris Peeters  Friday, July 14, 2006 12:50 PM

problem solved

this.da.Fill(dataSet2);
dataSet2.Tables[0].Clear();

good luck to everybody!!!

Araz Mustafa  Thursday, July 10, 2008 1:15 PM

Me.DataGridView1.Rows.Clear()

DMan1  Friday, July 14, 2006 1:24 PM

dataGridView1.Rows.Clear();

i used this code but there are error: cant clear the list;

how to do for clear datagrid view

Araz Mustafa  Thursday, July 10, 2008 10:21 AM

problem solved

this.da.Fill(dataSet2);
dataSet2.Tables[0].Clear();

good luck to everybody!!!

Araz Mustafa  Thursday, July 10, 2008 1:15 PM

// Background info :: this.dgSrchResults = new System.Windows.Forms.DataGridView();

/// <summary>

/// Clear datagrid

/// </summary>

private void ClearSearchGird()

{

DataTable tmp = new DataTable();

if (this.dgSrchResults.RowCount > 0)

{

this.dgSrchResults.DataSource = tmp;

}

}

Smile ... that Rows.Clear fail also under .Net 3.5 framework.

BeMobile  Thursday, October 23, 2008 9:30 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView CurrentRow Not Being Set
• Modifying BidingSource
• Nasty problem with datasource
• ComboBox in DataGrid using Mark's class
• when i changed my Trackbar value, how shall i update the value in Xml Database?????
• RowFilter Problem with DataView
• How do I skip a column using tab key in a datagridview
• Strange issue with DataGridView new rows
• About datagrid
• Asynchronous Delegate Call having a Responsive UI while Populating a ListBox