Home › Forums › WinForms controls › Xceed Grid for WinForms › Datarows Remove
I’m new to the Xceed grid Control. And I need some help.
I’m trying to remove unbound datarows, and didn’t get success I received de following Exception when remove method was called:
“Exception has been thrown by the target of an invocation.”
Dim objDatarow As Xceed.Grid.DataRow
For Each objDatarow In grdagents.DataRows objDatarow.Remove() NextDo you have any idea’s how I can solve this?
Thanks. Daniel Romaniuk
Imported from legacy forums. Posted by dRomaniuk (had 1998 views)
You cannot use a For Each on a collection from which you delete items in that very loop. You need to use a regular For loop, and go from DataRows.Count – 1 to 0, i.e :
For i = grdagentes.DataRows.Count – 1 to 0 Step -1 grdagentes.DataRows(i).Remove() Next i
However, you can simply use the DataRows.Clear(), and it will do it for you!
Imported from legacy forums. Posted by André (had 2946 views)