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
1185
How to delete a row when validation fails in custom datasource?
posted

I've got a small grid displays data from a many:many list - effectively the user is able to select multiple items from a reference list - but since these lists can be long, instead of showing a listbox with checkmarks, I'm using a grid, populated only with the selections made.

This works fine. A lookup list is used to edit the only column on the grid and it works nicely.

My problem is validation - the user cannot select an item that has already been selected in another row. Doing the actual check in the OnCellDataUpdating() method isn't a problem, and for existing rows, it nicely reverts to the original value. However NEW rows are another matter - the grid creates the new row at the time the user begins editing (and the datasource MUST create a new object in the internal list to match this before editing begins). Thus if validation fails for this new row - we end up with a new (blank) row on the grid, and a new "new row" line beneath it.

Now in an ideal world, I want to keep ALL my business/data logic in my custom DataSource class - so how do i notify the data source that a row should be deleted because the edit just completed was invalid?? If I try to access the parentRow collection directly and remove the row, it does work, but I get a rather ugly message displayed as well.

The alternative is to put code in the grid's AfterRowUpdate() event, and detect a marker left by the datasource for that row, indicating that it failed validation - and the row is selected and DeleteSelectedRows() is called. This works cleanly and gives the end-user-experience I want, but I consider it to be BAD design to be forced to split my validation logic like this. Not the least of which is that when I copy this datasource to several other grids on this form, and other forms, I now have to duplicate this code.

So, does the UltraDataSource have a way of removing rows internally, or is it a hole in the product that needs filling?

Parents Reply Children
No Data