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
615
Removing Multiple Rows in Code via UltraDataSource
posted

Hi All:

     I have the following code behind a button's click event, which removes records from my UltraDataSource (bound to my UltraGrid) if the "Age" field is zero (or null):

 

        Dim uRow As UltraDataRow

            For Each uRow In UltraDataSource1.Rows
                If  (uRow("Age") Is DBNull.Value OrElse DirectCast(uRow("Age"), Integer) = 0) Then
                    'Delete the row and raise the Event
                    UltraDataSource1.Rows.Remove(uRow, True)
                End If
            Next

 

     The problem is that it deletes every OTHER row.  If I enter "0" for the Age in rows 1, 2, and 3, rows 1 and 3 will be deleted but row 2 will not.  If I enter "0" for the age in rows 1, 3, and 5, all three rows are deleted successfully.

     Any reason why it won't delete consecutive rows?

Kevin

Parents
  • 12773
    posted


    Hello Kevin ,

    Here is a smple code how to remove items form ultradataSource. Fireing the event RowDeleted and
    and removing the item form external data will be sinchronized in this way:
    Me.externalData.Rows.RemoveAt(e.Row.Index)

    Private Sub button1_Click(sender As Object, e As EventArgs)
        Dim rowItemsToRemove As New List(Of UltraDataRow)()
            For Each item As UltraDataRow In ultraDataSource1.Rows
            Dim value As Object = Me.ultraDataSource1.Rows(item.Index).GetCellValue(2)
            Dim intValue As Integer

            If TypeOf value Is System.DBNull OrElse (Int32.TryParse(TryCast(value, String), intValue) AndAlso intValue = 0) Then
                rowItemsToRemove.Add(item)
            End If
        Next

        For Each rowItem As UltraDataRow In rowItemsToRemove
            ultraDataSource1.Rows.Remove(rowItem, True)
        Next
    End Sub


    I hope this helps.

    Best regards,
    Dimi
    Developer Support Engineer
    Infragistics Inc

Reply Children
No Data