This is a migrated thread and some comments may be shown as answers.
Row Editing End Event
7 Answers 34 Views
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 15 May 2018, 01:49 PM

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).

 

Thanks, Massimiliano

7 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 18 May 2018, 08:14 AM
Hi Massimiliano,

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.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
n/a
Top achievements
Rank 1
answered on 22 May 2018, 08:26 AM
Thanks for your reply, I have studied your example, and it is clear, but the question I asked is conceptually different. In your example, associate the error with a property of the model you are using (the length of the "country"). What would serve for me is an event that triggers at the end of the editing of the cell, so that in that event I can write the code that serves for my validation. In your example, a validation similar to the one I would like to build is that on the change of city I can check, for example, that the inserted city is one of "Rome", "Paris" and "Berlin" (and also that no numerical characters are entered) . Knowing that the logic that builds the control elements is independent of the model (the 3 capitals I mentioned are 3 strings, in a list of strings, but which is not part of the model)
0
Nasko
Telerik team
answered on 23 May 2018, 08:35 AM
Hello Massimiliano,

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.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
n/a
Top achievements
Rank 1
answered on 24 May 2018, 10:03 AM

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 :

<telerikDataGrid:DataGridPickerColumn PropertyName="VatP" CellContentFormat="{}{0:N}"
                                 HeaderText="VAT P" Width="100" SizeMode="Fixed" ItemsSource="VatRate" >
    <telerikDataGrid:DataGridTextColumn.CellDecorationStyle>
        <telerikDataGrid:DataGridBorderStyle BorderThickness="1, 0.5, 0.5, 0.5" BorderColor="White" />
    </telerikDataGrid:DataGridTextColumn.CellDecorationStyle>
    <telerikDataGrid:DataGridTextColumn.HeaderStyle>
        <telerikDataGrid:DataGridColumnHeaderStyle OptionsButtonTextColor="Transparent" BackgroundColor="Black" TextColor="White"
                                                   HorizontalTextAlignment="Center" TextFontSize="10"
                                   BorderColor="#D9D9D9"
                                   BorderThickness="1"/>
    </telerikDataGrid:DataGridTextColumn.HeaderStyle>
    <telerikDataGrid:DataGridDateColumn.CellContentStyle>
        <telerikDataGrid:DataGridTextCellStyle TextColor="White" FontSize="12" SelectedTextColor="White" HorizontalTextAlignment="End">
        </telerikDataGrid:DataGridTextCellStyle>
    </telerikDataGrid:DataGridDateColumn.CellContentStyle>
</telerikDataGrid:DataGridPickerColumn>

 

Where VatRate is a simple object with decimal property :

public class VatRate : ModelObject
{
    public decimal vat;
 
    public decimal VatP { get => vat; set { vat = value; RaisePropertyChanged("VatP"); } }
 
    public VatRate()
    {
    }
}

 And modelObject is this :

public class ModelObject : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
 
    protected void RaisePropertyChanged(string name)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}

 

And i've in .cs code beheind i create a LoadVatRateMethod :

private void LoadVateRateSource()
{
    VatRateListTest = new ObservableCollection<VatRate>();
    List<decimal> vatRateList = new List<decimal>() { 10, 5, 15, 22 };
 
    foreach (var item in vatRateList )
    {
        VatRate myVat = new VatRate();
        myVat.VatP = item;
        
        VatRateListTest.Add(myVat);
    }
 
 
}

 

where VatRateListTest is an object of VatRate type. When i edit row nothing is displayed in Vat P colum

0
n/a
Top achievements
Rank 1
answered on 24 May 2018, 01:32 PM
However, I still need to intercept the end of the moment of editing to start other functions
0
n/a
Top achievements
Rank 1
answered on 24 May 2018, 03:48 PM
I decided to create an event that I subscribe to from the calling page that I trigger on the execute method of the CustomValidateCommand class. I am left with a perplexity due to the fact that the Execute method is performed twice and I can not understand why.
0
Nasko
Telerik team
answered on 25 May 2018, 10:07 AM
Hello Massimiliano,

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:
https://feedback.telerik.com/Project/168/Feedback/Details/250364-datagrid-validation-command-is-called-twice

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:
public class CustomValidateCommand : DataGridCommand
{
    private static int validationCount = 0;
 
    public CustomValidateCommand()
    {
        this.Id = DataGridCommandId.ValidateCell;
    }
 
    public override void Execute(object parameter)
    {
        if (validationCount > 0)
        {
            validationCount = 0;
            //Execute your logic here.
        }
        else
        {
            validationCount++;
        }
    }
}

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.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
n/a
Top achievements
Rank 1
Answers by
Nasko
Telerik team
n/a
Top achievements
Rank 1
Share this question
or