delete rows from datagrid

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
I'm doing the following :

Dim dsDeleted As New DataSet
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)
dgDeleted.DataSource = dsDeleted

basically I create a dataset dsDeleted that gets all the rows deleted
in dsEquivalents, and I fill a datagrid dgDeleted with this dataset.
My problem is that whatever rows I delete, dgDeleted is always empty
and does not seem to get the deleted rows.

What should I do to store the deleted rows in a dataset so i can
proceed to further operations ?

Thx
 
Hi Sam,

From the MSDN:
Gets a copy of the DataSet containing all changes made to it since it was
last loaded, or since AcceptChanges was called

Did you call Acceptchanges?
 
Sam,

A datagrid does not show deleted row, and that change is not changed.

Maybe you can use the RejectChanges method on that extra dataset, that you
made with getchanges. (Know that new added rows which are deleted are not
seen as deleted however directly will removed with a delete).

I hope this helps,

Cor
 
thx
I've changed my code to this :

Dim dsDeleted As New DataSet
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)
added line ---->dsEquivalents.AcceptChanges()
dgDeleted.DataSource = dsDeleted

but dgDeleted is still empty. I don't know why :(
 
Sam,

Try:
added line ---->dsEquivalents.AcceptChanges()
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)
 
Cor,
This new added datagrid was just to see if my rows were properly marked
as deleted anyway. I do not intend to keep this datagrid.
But apparentely my deleted rows are NOT marked as deleted as I would
assume they would be added to this datagrid otherwise. Basically I want
my dsDeleted dataset to contain rows that are marked as deleted so that
I can call a stored procedure according to what is in this dataset.
Any idea what might go wrong ?

thx
 
Sam,

Sorry I meant:

added line ---->dsEquivalents.AcceptChanges()
'Code wich deletes the records
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)

Also try this to see if there are changes:
If Not myDataSet.HasChanges(DataRowState.Deleted) Then Exit Sub

And if you are filling the dataset with records yourself (not database)
try also the AcceptChangesDuringFill = false property.
 
Sam,

Did you try that

Dim dsDeleted As New DataSet
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)

dsDeleted.RejectChanges

dgDeleted.DataSource = dsDeleted

Cor
 
Pipo,
I've tried that.
Then dsDeleted' s value is 'Nothing', and doesn't contain any of the
deleted rows in dgEquivalents.
 
Back
Top