This code (VB.NET) works, but it deletes the wrong items:
Dim i As Integer = 0 Dim uRow As Infragistics.Win.UltraWinGrid.UltraGridRow Dim cnt As Integer() Dim iSelCnt As Integer
iSelCnt = Me.ugrdDTLogLog.Selected.Rows.Count If iSelCnt > 0 Then
ReDim cnt(iSelCnt)
For Each uRow In Me.ugrdDTLogLog.Rows If uRow.Selected = True Then cnt(i) = uRow.Index i = i + 1 End If
Next
For i = cnt.Length - 1 To 0 Step -1 Me.ugrdDTLogLog.Rows(cnt(i)).Delete(False) Next
End If
DUH. Just found the DeleteSlectedRows method on the wingrid.
DeleteSelectedRows is probably easier.
But just for future reference, you should never use a ForEach loop to remove items from a list. The reason your code doesn't work correctly is that you are modifying the list as you are looping through it and this will mess up the indexer.
One way to handle something like this would be to loop through the list and build a separate list of items you want to remove. Then you could loop through the second list and remove the items from the original list.
Another way, which is what I personally prefer, is to loop through the list backward. That way removing an item doesn't affect the index of any of the items the loop will examine in the future.
My blog entry shows the code with a bindingsource attached to a controller expample doing a reverse delete like you mentioned :)
http://nickturner.wordpress.com/2009/12/10/deleting-multiple-items-from-ultrawingrid-vai-a-controller/