Hi, in my code i must enter a check on the entered value during edit mode (like a custom validation). There is an Telerik.Grid event that triggers this moment where i can check the validation (UI must disable some controls in the page until "logical" validation is not ok, so user can insert an invalid value, but i want control that user choose one valid value before re-enable this controls).
7 Answers, 1 is accepted
The DataGrid control provides a Validation functionality out of the box. The control also provides ValidateCell command that you can use to handle the errors (if there are such) and make any desired visualization.
I have prepared a sample for you that demonstrates the validation functionality of the DataGrid - please, check it.
Hope this helps.
The DataGrid control does not provide an event, but provides a command that is invoked when editing is about to end.
So, in order to achieve the desired by you functionality you can create a custom CommitEdit command and write your validation there. Inside the command you can get the value of the cell your are currently editing and based on the validation logic either to invoke the command or to prevent finishing the edit operation until valid value is entered.
I have modified the sample sent in my previous response with the described above approach and you can give it a try.
I hope this will be helpful for you.
Thank Nasko, but i've other questions about your solution. CustomValidateCommand instance is starting on costructor of the page where i use the telerik grid. It's work fine, but i don't understand who call Execute Method (i asked you because i want set parameter to pass to Execute Method where i can set some object (page properties), that i can investigate when execute method is finished.
For Example, imagine that I have "Boolean" values on the page that establish the validity of the data present on it. Among these values there are some related to the data entered in the grid. for example, we hypothesize that I have a Boolean telling me (going back to the example I mentioned a few days ago) if the city I entered is in the list of "valid" cities. We will then have a property on the grid page called "IsValidCity". How can I return the real value of this property to the page from the Execute method? In the constructor I can of course pass different parameters (for example the list of valid cities). I can then assign a property to the CustomValidateCommad object which is evaluated on the basis of what is passed by the manufacturer and can therefore at that point in the Execute determine if the inserted city is "valid". How can I return this value back? Assuming that there are several lines, I would like to assign "False" to this property if in at least one of the lines there is an invalid city (if I understand correctly the execute I have the focus of the single line I am modifying). The alert can not be used because the page logic requires different behavior. A possible work around would be to use a pickerColumn, but I have another problem, since the list of valid external cities (which is part of another object), I tried to load the data inside an ObservableCollection, but at the moment I do not see the objects contained in the ItemSource on the picker column.
In my gridView i add this column :
Where VatRate is a simple object with decimal property :
And modelObject is this :
And i've in .cs code beheind i create a LoadVatRateMethod :
where VatRateListTest is an object of VatRate type. When i edit row nothing is displayed in Vat P colum
The approach you have found with the event is really nice. Also, your observation about the validation command are absolutely right - it has been called twice.
The first time is called by the CanExecute method of the CommitEdit command and the second time from the Execute method of that same command. I have logged this issue in our feedback portal and on the following link you can track its status - if you subscribe to the item once its status gets changed you will be notified:
As a workaround until the issue gets fixed I can only suggest to invoke your event when the Validation is invoked the second time - this is the time that gets called when the Execute method of the Commit command is validating the value. Here is a sample code you can use:
I apologize for the inconvenience the issue might be causing you. I have updated your Telerik points for bringing this to our attention.
If you have any additional questions or concerns regarding Telerik controls, please let me know.