Delete a DataGrid Row

E

Eric

How can you delete a DataGrid item row? I found a couple threads on
how to hide the row (using MyDataGrid.Items(n).Visible = False). This
does work, but I need to physically remove the information from the
grid, not just hide it. Any ideas?

Thanks in advance,

Eric
 
A

Alvin Bruney

The datagrid retrieves its data from the underlying datasource which is
usually a dataset. The simplest way is to just remove the row in the dataset
and rebind the datagrid. If it is not in the dataset, it cannot possibly
show up in the datagrid. You would need to first find the row to be deleted
(from the selecteditem) and just do a find on the dataset and use the delete
property of the dataset row to clean out the dataset.
hth
 
E

Eric

Thank you, Alvin...a perfect, simple suggestion. (Why didn't I think of that!?)

Thanks again,

Eric
 
R

Raven Brooke

This was my first thought also, but what is the syntax for finding the
row in the datasource? I get as far as:

ds.Tables["dt"].Rows.Remove(what goes here?)
 
A

Alvin Bruney

the argument takes a datarow object
here is a quick example

DataRow foundRow = myDataRowCollection.Find(lblID.Text)
if(foundRow != null)
myDataRowCollection.Remove(foundRow)

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top