Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
Is it possible to remove a row(s) from the BeforeRowsdeleted row collection
posted

Lets say that i select 4 rows to be deleted and hit delete.  I would now like to verify something per row and if the row fails i would like to remove it from the "to be deleted" collection. So if 1 of my 4 rows fails then only 3 will be deleted.

For Each aRow As Infragistics.Win.UltraWinGrid.UltraGridRow In e.Rows
    Ticket = Lookup("tblSchedule", "ID", "InvoiceID=123")
    If GP.IsNotBlank(Ticket) Then
        'This is where i would like to remove the row
    End If
Next

 

  • 10
    Suggested Answer
    Offline posted

    I solved this by iterating through all the rows (like you are doing) and select them first, then after the loop is complet call the DeleteSelectedRows method from the UltraGrid object.

    I.E.

    For Each aRow in e.Rows...

      If GP.IsNotBlank(Ticket)...

         aRow.Selected = True

      End If

    Next

    e.DeleteSelectedRows()

    I'm using this in 14.2 right now.

  • 17259
    Suggested Answer
    Offline posted

    Even if you that, C# doesn't allow to alter a collection in the middle of a foreach loop.

    You can write this in the event handler to cancel the deletion and initiate your own:

     

     

    e.Cancel =

    true;

    ultraGrid1.EventManager.SetEnabled(

    GridEventIds.BeforeRowsDeleted, false);

    e.Rows[0].Delete(); // or any thing else you want to delete

    ultraGrid1.EventManager.SetEnabled(

    GridEventIds.BeforeRowsDeleted, true);