.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

DataGrid exception on validation failure (DeferRefresh is not allowed...)

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :WPF
In the same series as the DataGrid validation scheme issues, I get an exception when a cell is invalid the DataContext changes This happens in a DataGrid, which is bound to a CollectionViewSource. This CVS itself has a DataContext bound to the currently selected product of a ListBox. So we are editing the details of product, those details include a data list in a DataGrid (DataGridTextColumn in this case). Either by using a data type that implements IDataErrorInfo or by using a ValidationRule, if the validation fails the DataGrid reacts by keeping the TextBox and showing a red box around it (when the validation is OK, the cell is tranformed back to a TextBlock). Nothing prevents me from selecting another product. The DataGrid then shows the new data and everything is fine. But if I come back to the product which failed validation, I get this exception: InvalidOperationException, 'DeferRefresh' is not allowed during an AddNew or EditItem transaction. How can I prevent that? What is the correct way of cancelling the edit on that faulty cell when another product is selected, or when the DataContext changes? I can detect those events, but CancelEdit() doesn't work on the DataGrid (no result). I'm using .NET 4.

View Complete Post

More Related Resource Links

DataGrid ValidationRule or IDataErrorInfo validation code called multiple times for each data change

Following my enquiry regarding a problem in Datagrid validation, for which managing exceptions is apparently a problem, I tested the two other methods: using validation rules, or implementing the IDataErrorInfo interface. I ran into other problems there, more insidious this time. This has been done on Windows7 (32-bit), .NET 4.0.30319. 1) IDataErrorInfo When this interface is implemented, the this[string columnName] property is called four times for each modification: two times before the cell enters edit mode (with the old value in the corresponding property) two times when the new value has to be validated (with the new value) It strikes me as not really efficient, is there something wrong with my code? Here's the C# part: using System; using System.Windows; using System.Collections.ObjectModel; using System.ComponentModel; namespace DataGridTest2 { public partial class MainWindow : Window { ObservableCollection<User> users; public MainWindow() { InitializeComponent(); users = new ObservableCollection<User>() { new User { Name = "Teddy", Age = "2" }, new User { Name = "Avi", Age = "19" } }; datagrid.ItemsSource = users; datagrid.Focus(); } } public class User : INotifyPropertyChanged, IDataErrorInfo { string name; public string Name

'DeferRefresh' is not allowed during an AddNew or EditItem transaction.




I have this exception when using my application. I know more or less where it comes from :

My application uses tabs. I open a tab containing a datagrid. When i double click on a cell, it automatically creates a new object (in the collection binded). However, lets say my cell is still in editing mode. If i open a new tab, and then want to go back in the previous one, I get this error message.

To avoid this problem, I would like my cell to stop editing mode anytime i click somewhere else.

Thanks by advance for your help.



WPF DataGrid.Items.Refresh Exception


I am getting this exception when calling the Refresh method of a datagrid.items.  Any clue how to solve this?

This is the message:  'Refresh' is not allowed during an AddNew or EditItem transaction


Dynamic TextBox Validation not working on dynamic DataGrid on PlaceHolder



I have a placeholder to which I programmatically add DataGrids... In the DataGrids, I programmatically add TextBoxes along with dynamic validations. Somehow, the DataGrids show up, but the dynamic validations don't work. If I set them to static, the blank space for them appears, but still, they wont work.

I'd appreciate your help on this.



Datagrid Validation depending on whole collection - enforcing unique values


I have a situation where I have an IList<T> collection of objects bound to a datagrid. I have one property, name, bound to a DataGridTextColumn. I want to enforce the rule that name should be unique within the collection and was wondering what might be the best way to do it.

Most of the validation examples I've seen either validate a single cell or else validate a row, allowing you to compare several values within the same row. But I need to validate the value of a single cell based on the values in the entire collection.

Field validation failure on not required/blank drop-down box


I have a column in my list that is based on the records in another SharePoint list. When I try to edit a record in Datasheet View, I frequently get the following validation rule failure message:

The text entered for Client Impacted isn't an item from the list. Select an item from the list, or enter text that matches one of the listed items.

Even though the column appears to be blank to the naked eye, when you double click in the column, it selects what appears to be a space character and when you hit the delete key, it now passes the validation rule. So, my assumption is that the validation rule is saying something like "Space character isn't in the list, so you can't save the record..." Here's what's odd. I do NOT get the same validation rule warning when I edit in standard view and I know for sure that the column has not been erroneously filled with a space character. Anyone have any idea what might be going on here?

Thanks in advance for your help.


Detecting cell validation errors from a DataGrid

Is there a way, from the DataGrid, to work out if any of it's rows have a validation error? I know you can use the Validation.HasError property at the level of an individual cell, but it seems that information doesn't filter back up to the DataGrid so you can test a simple property on the DataGrid to see if there are any errors (i.e. if you get Validation.HasError at the DataGrid level, it's always false regardless of whether or not there are any errors).

List Item Update Exception from HRESULT: 0x80040E2F Unexpected query execution failure, error code 3


A thread somewhat simliar to this has been posted before as well, but i just wanted to detail out the issue and circumstances

We have a list with 53 columns and 2600 items(and growing. I know its rubbish, but thats the way it is at the moment). The list was created using SharePoint GUI  on a test server, saved as a template with data, and was then imported to the production environment. I can post the list columns and type if it helps.

Every one in a while, on updating an item, SharePoint throws up the very not so helpful error page with "Exception from HRESULT: 0x80040E2F".

We looked into the logs and found that for each suc error, there was a Database level error logged as well.

The error starts with Unexpected query execution failure, error code 3621. Additional error information from SQL Server is included below. "The statement has been terminated." Query text (if available): "BEGIN TRAN;DECLARE... and runs for many lines so i wont post the entire blurb here.

Each time, the item update is successful, despite this error. The list also has an Item Updated event handler attached to it. Every time the update error occurs, the event handler does not seem to be firing.

Anybody can shed light on what is happening. We have tried exporting the list template to another site and everything seemed to work

Failure sending mail: Exception 0xc0000005 was generated at address 0x000007FEE3D4122B Mail will not


I'm running SSRS 2008R2.  I'm getting the above error a a couple of email subscriptions.  Some email subscriptions work, a few I'm getting this error message.  I've seen the posts about resetting IIS, SSRS and Agent Service.  I've done this, and it does seem to temporary fix the issue, but then it comes back. 

The one post where it says the "From" field containing more than 255 characters.  This is not my situation.

I need to find a more permanent fix for this issue.  Does anybody have any further insight.  Some postings seem to be related to older versions of SSRS.  I'm on the latest.



Any help or suggestions would be appreciated.

How to add validation rule programmatically on datagrid column, whose itemsource is datatable?

I want as user ends editing a datagrid cell, a validation rule should be applied on this cell for error checking like whether its value is null or not and in case of null it should display the error on that cell. All this i want to do programmatically not in xaml. Can anybody guide me with an example ?

Page Error Validation Exception


hello fellows

i would very much like to capture certain dal/bll exceptions in my page_error code and turn them into validation errors

so they should show up in the validationsummary

this is the code im trying now

    Protected Overrides Sub OnError(ByVal e As EventArgs)
Dim ex = Server.GetLastError
If ex.GetType = (New ArgumentException).GetType Then
Dim validator = New CustomValidator
validator.IsValid = False
validator.ErrorMessage = CType(ex, ArgumentException).Message
End If
End Sub
End Class

the logic is simply to catch only exceptions of type ArgumentException, otherwise it should bubble up (to global.asax handling)

what hapens is that after this code block runs, the exception still exists in the system, so it always bubbles up to the global.asax

it there any way to tell asp.net that "its ok, i took care of the exception, just continue with the page"?

i tried server.clearerror and context.clearerror but these methods stop the whole page and return a blank empty page

thank you all for your time and patience

p.s. if u have any other ideas 4 improving this code, pl

Invalid Exception in Datagrid


There is a code as following:

switch (((System.Web.UI.WebControls.LinkButton)e.CommandSource).CommandName)
                    case "statusActive":
                    case "statusClosed":

I am getting the following error:

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.


Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

Use Jquery with repeater, gridview, datagrid

Before we talk about jquery inside any itemtemplate (repeater, gridview, datagrid), we need to understand the basic use of jquery functions

ListBox tricky to set in a DataGrid/GridView

Listboxes are very tricky to set selected items in grid - there is no real nice way to do it. It would have been great if Microsoft included a property that accepts an array or comma separated values - or anything! But they only allow each item in the list to be selected individually. The way to do this in a grid is a bit messy, but it is fairly simple to implement. When a row is created (as per the event), select the items of the listbox as per the datagrid source data:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend