I have a checkbox for all rows in the grid. I want the user to be able to delete multiple rows by selecting as many as they want and then hit "delete." Kind of like email in Gmail/Yahoo, etc.
I have two issues.
One, I get a warning for every row that the user tries to delete. Can I suppress this warning? I can't find the setting anywhere.
Two, when the last row tries to delete in my foreach loop, I get an error:
InvalidaOperationException... Any idea what's going on here and how to fix this? It happens on the last selected is to be deleted... Please let me know your thoughts. I seearched the forums and couldn't find anything.
Really? I didn't think about that -- but my datarows don't have any distinct ID for me to know which row to delete at this time. So I really wouldn't know which row in my source I was deleting unless I gave them all ids..
WAY to much overhead, just remove it from the datarow.
This does it (I'd still like to know if there's a better way):
public static void RemoveSelected(string columnKey, JWWinGrid grid) { List<UltraGridRow> rows = new List<UltraGridRow>(); //Do not want to modify grid rows that are being iterated through //in the foreach loop. Rather, collect them and delete them outside //the loop. foreach (UltraGridRow row in grid.Rows) { if ((bool)row.GetCellValue(grid.Columns[columnKey])) { rows.Add(row); } } foreach (UltraGridRow row in rows) { row.Delete(false); } }
When dealing with "ANY" type of databound list in windows you DO NOT delete from the list itself as when you delete the index changes so by removing the row from the dataset you will avoid problems like this for "ANY" list not just infragistics.
Looking at the stacktrace, I can only guess that it's trying to move to the next row, which doesn't exist because I deleted it. It's like I need to refresh the foreach loop somehow... Hmmm...
So I'm guessing I can't iterate through the rows and move them that way? But when I try to delete the last row, of just one row, I get this error. Hmmm...
System.InvalidOperationException was unhandled by user code Message="" Source="Infragistics2.Shared.v7.3" StackTrace: at Infragistics.Shared.SparseArray.CreateItemEnumerator.EnsureNotExhausted() at Infragistics.Shared.SparseArray.CreateItemEnumerator.System.Collections.IEnumerator.MoveNext() at Infragistics.Win.UltraWinGrid.RowEnumerator.MoveNext() at ...RemoveSelected(String columnKey, JWWinGrid grid)...