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.
In case anyone wanted to see my code:
public static void RemoveSelected(string columnKey, JWWinGrid grid) { foreach (UltraGridRow row in grid.Rows) { if ((bool)row.GetCellValue(grid.Columns[columnKey])) { row.Delete(); } } }
Okay, found the "displayPrompt" as a possible overloaded argument. I still don't know how to delete multiple rows without getting an error!! Seems like the grid might be refreshing on each delete which is causing me some issues...
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)...
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); } }
WAY to much overhead, just remove it from the datarow.
Hi Jit,
You should post this in the appropriate WPF forum. Thi forum is for the Windows Forms grid, so I'm afraid I can't help you with XamDataGrid.
I'm getting the same error . But in my case I'm not deleting any rows . I'm removing column from front end from xam datagrid . And when again try to bind data to xam datagrid It's throws unhandled exception "Enumerator Has Exhasued"
at Infragistics.Collections.SparseArray.CreateItemEnumerator.EnsureNotExhausted() at Infragistics.Collections.SparseArray.CreateItemEnumerator.System.Collections.IEnumerator.MoveNext() at Infragistics.Windows.DataPresenter.RecordCollectionBase.RecordEnumeratorBase.MoveNext() at Infragistics.Windows.DataPresenter.AutoSizeFieldLayoutInfo.OutOfViewRecordEnumerable.Enumerator.MoveNext() at Infragistics.Windows.DataPresenter.AutoSizeFieldHelper.RecordEnumeratorBase.MoveNext()
Any thing I'm missing ?
Another option would be to select the rows and call the DeleteSelected method on the grid.
Got ya, well and I am going to eventually be saving this data offline, so yes I agree it needs to be done. I'll do it now so that I can delete my rows more efficiently. Thanks for the advise..
When building a list (of any type, combo, grid etc) it is important to make sure that you pass a ID that can be referenced by the grid and data at the same time this is just a good habbit as if you have to access the data for any means (ie: update/insert,select from where) you have the corosponding record...
You need to go back and add a UID to each row and will make your life A LOT easier as the grid is just a repensitation of your database nothing more...