Datagrid clear and add records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is for a Win form.

How do I clear all the rows in a datagrid?

How do I add a record to a datagrid?
 
to remove all the rows from datagrid clear out all the rows from what ever
you have bound to the grid

to add a row to the datagrid add an entry to the what ever you have bound to
the grid

HTH

Ollie Riches
 
Hi Cadel,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to remove all rows from the
datagrid. If there is any misunderstanding, please feel free to let me know.

I agree with Ollie that this depends on what data source the datagrid is
binding to. When we need to modify the contents in the datagrid, we don't
modify the control itself directly. We have to change the underlying data
source, and the modification is show on the datagrid.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Yes, I would like to see a code sample of clearing out all the rows in a
datagrid. If its not too much trouble I would ALSO like to see code sample
of one row being removed that the user selects.

I haven't coded the data source for the data grid that its binding to, yet.

What do you suggest? I want the user to select from a drop down box what
license type, and then click a button to add the license type to a datagrid.
When the user finishes adding license types to the datagrid, then the user
will click on the complete button. At that point I want the data sent to MS
SQL server.
 
Hi Cadel,

If your DataGrid is binding to a DataTable like:

this.dg.DataSource = dataTable

You can use dataTable.Clear() to clear out all the rows.

If you need to remove the selected row in a datagrid, you have to get the
CurrencyManager first and then use DataRowView.Delete to remove it. Here's
a code sample.

CurrencyManager cm = (CurrencyManager)this.BindingContext[dataTable];
DataRowView drv = cm.Current;
drv.Delete();

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top