Grid and delete

Posts   
 
    
LoneEagle
User
Posts: 6
Joined: 08-Jul-2005
# Posted on: 15-Jul-2005 20:41:41   

Hi,

Mode : Adapter Using : MS Visual Studio 2005, .Net 2.0, Infragistics WinGrid

Problem : When deleting a row in the grid, this will remove it from the collection that row. When saving (adapter.SaveEntityCollection(...)), that row will not be deleted from the Database.

Is one solution would be to keep a list of deleted entity on the Grid delete event and pass that list to the server on save (not great)?

With a Dataset, the row is not removed from the collection but marked as Deleted (RowState). This allow the server to know what has been inserted, modified or deleted. The Grid is displaying only rows that are not deleted, even they are in the collection.

What is the best solution?

Thanks

Allen

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 15-Jul-2005 21:45:45   

LoneEagle wrote:

Is one solution would be to keep a list of deleted entity on the Grid delete event and pass that list to the server on save (not great)?

That's sorta what I do. Creat an arraylist of deleted idents in the BeforeRowsDeleted event. Then, delete them in the AfterRowsDeleted event.

Here is a poor example.

    Private Sub grdAppCategoires_BeforeRowsDeleted(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs) Handles grdAppCats.BeforeRowsDeleted

        Dim Row As Infragistics.Win.UltraWinGrid.UltraGridRow

        _DeletedIdents = Nothing
        _DeletedIdents = New ArrayList

        For Each Row In e.Rows
            _DeletedIdents.Add(CType(Row.ListObject(), SOITC.Guardian.LLBL.EntityClasses.AppCategoryEntity).AppCategoryIdent)
        Next

    End Sub

    Private Sub grdAppCategoires_AfterRowsDeleted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grdAppCats.AfterRowsDeleted

        Dim Ident As Integer
        Dim ErrorMessage As String

        For Each Ident In _DeletedIdents
            _MyAppCategory.DeleteEntityByIdent(Ident, ErrorMessage)
            If Not ErrorMessage Is Nothing Then
                MessageBox.Show(ErrorMessage)
            End If
        Next

        _MyAppCategory.LoadAppCategorys()

        grdAppCats.DataSource = _MyAppCategory.AppCategorys.Items

    End Sub

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-Jul-2005 14:32:04   

Like fishy says, use a collection to track the entities to delete and you can then utilize the UnitOfWork to perform save and deletes in one go. You can also add a removed entity to the unitofwork directly if you want.

Frans Bouma | Lead developer LLBLGen Pro