Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > clearing a datagridview
 

clearing a datagridview

Hi! how can i clear all the cells of the datagridview (when are bounded) this is my scenario:

i use a DataGridView to register products for a sale ticket, but if i decide cancel the ticket i have to clear the products, there is an event, datagridview.clear but it returns "the list cannot be cleared" something like that

Oscar Marquez  Wednesday, December 28, 2005 2:54 AM
To clear a DataGridView, clear the data to which the DataGridView is bounded.  If that's a DataTable, for instance, it has a Clear() function of its own.
paulains  Wednesday, December 28, 2005 6:57 AM
To clear a DataGridView, clear the data to which the DataGridView is bounded.  If that's a DataTable, for instance, it has a Clear() function of its own.
paulains  Wednesday, December 28, 2005 6:57 AM
If you set the RowCount property to 0, all rows will be removed from the DataGridView. This is equivalent to calling the DataGridViewRowCollection.Clear method.
Logifire  Friday, June 01, 2007 7:29 AM

I tried the above two suggestions, but neither worked. I tried setting the DataSource of the DataGridView to null and that worked.

dataGridView.DataSource = null;

Milo Minderbinder  Tuesday, July 10, 2007 5:39 PM

DataGridView1.RowCount = 1

DataGridView1.Rows.Clear()

Cuando cambio el DataGridView1.RowCount se ejecuta automaticamente

Grid_CurCellChange de DataGridView1, tiene que tener encuenta este evento

When change the DataGridView1.RowCount, executes Grid_CurCellChange in DataGridView1 automatically, this event must have

De Juan Grullon

jqgrullon@gmail.com

Juan Grullon  Wednesday, November 12, 2008 3:44 PM

Okay, say you have a table adapter called someTableAdapter and a data set called someDataSet that has a table called someTable.Try something thatlooks like this:

someTableAdapter.FillByClearDataset(someDataSet.someDataSet)

joshdbaker  Wednesday, December 10, 2008 12:29 AM
al salam alykom
السلام عليكم
peace upon with you
_________________________

i found a solve for this trick
follow the steps if you deal with the data like this way

first you regally have a connection to some database

2- you got this data into datatable to the datagrid view

like that

con as connection

cmd as command

dr as datareader

tb1 as datatable

now you opened the connection

and put the data into the data table like that

cmdon.Connection = cn
        cmdon.CommandType = CommandType.Text
        cmdon.CommandText = "Select * from table "
        dr = cmd.ExecuteReader
        tb1.Clear()
        DataGridView1.DataSource = tb1
        tb1.Load(drgrid)
        DataGridView1.DataSource = tb1

it'll work with you



samehsenosi  Tuesday, September 15, 2009 12:37 PM

You can use google to search for other answers

Custom Search

More Threads

• read data from RS232 in C# windows
• enabling controls
• Drag and Drop Datasources have all stopped updating
• DataGridView, Binding Navigator, and Multiple BindingSources
• Need Help With DataGridView
• How to install database in client machine
• DataGridViewTextBoxCell that supports 'overflow'...
• VB2005 Multiple Columns in combobox
• about DataGridView + EditingControl
• Good practice : Using dataset with 2 tables