This is a migrated thread and some comments may be shown as answers.

Row Error Template

9 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Koren
Top achievements
Rank 1
Koren asked on 08 Aug 2011, 07:12 PM
I am using RowValidating to catch duplicate records for one of my grids.  I add a validation result to the first cell and set e.IsValid to false.  This works just as I would expect in edit mode.  However, when I add a new row and get this error, it stops the save correctly and moves the cursor to the first cell with the tool tip showing but the row itself does not go red like it does in Edit mode.  Do I need to do something different for a new row to get the error template to show?  Do I need to change the error template?

thanks!

9 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 09 Aug 2011, 09:56 AM
Hello Koren,

 
May post more info about how the grid is bound to and the source-code behind RowValidating event handler?
 

Greetings,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Koren
Top achievements
Rank 1
answered on 09 Aug 2011, 04:14 PM
Here is the relevant code behind:
private void grdEnterprise_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            this.grdEnterprise.CurrentColumn = this.grdEnterprise.Columns.OfType<Telerik.Windows.Controls.GridViewColumn>().First();
            e.NewObject = new EnterpriseRecordViewModel(_enterpriseViewModel);
 
            this.grdEnterprise.KeyboardCommandProvider = new InsertKeyboardCommandProvider(this.grdEnterprise);           
        }
 
        private void grdEnterprise_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            this.grdEnterprise.KeyboardCommandProvider = new DefaultKeyboardCommandProvider(this.grdEnterprise);
            //this.grdEnterprise.KeyboardCommandProvider = new CustomKeyboardCommandProvider(this.grdEnterprise);
 
            if (e.EditAction == GridViewEditAction.Cancel)
            {               
                 
                return;
            }
            else
            {               
                //Update the entry in the view model
                if (DataContext is EnterpriseViewModel)
                {
                    _enterpriseViewModel.UpdateEnterpriseRecordCommand.Execute(e.NewData);                   
                }               
            }
        }
        private void grdEnterprise_Deleting(object sender, GridViewDeletingEventArgs e)
        {
            //delete the objects from the source
            foreach (object itemToDelete in e.Items)
            {
                _enterpriseViewModel.DeleteEnterpriseRecordCommand.Execute(itemToDelete);
            }
        }         
 
 
        private void grdEnterprise_RowValidating(object sender, GridViewRowValidatingEventArgs e)
        {           
            if (DataContext is EnterpriseViewModel)
            {
                if (e.Row != null)
                {
                    e.ValidationResults.Clear();
 
                    var _enterpriseRecord = (EnterpriseRecordViewModel)e.Row.Item;
                    bool _hasDuplicate = false;
 
                    int _itemCount = 0;
 
                    foreach (EnterpriseRecordViewModel _enterpriseRecordViewModel in _enterpriseViewModel.EnterpriseRecords)
                    {
                        if (_enterpriseRecordViewModel.TransactionCodeID == _enterpriseRecord.TransactionCodeID &&
                            _enterpriseRecordViewModel.FarmYearEnterpriseID == _enterpriseRecord.FarmYearEnterpriseID)
                            _itemCount++;
                    }
                    if (_itemCount > 1)
                        _hasDuplicate = true;
 
                    if (_hasDuplicate)
                    {
                        GridViewCellValidationResult _validationResult = new GridViewCellValidationResult();
                        _validationResult.PropertyName = "TransactionCode";
                        _validationResult.ErrorMessage = "Duplicate Transaction and Enterprise codes are not allowed";                       
                        e.ValidationResults.Add(_validationResult);
                        e.IsValid = false;
                    }                   
                }
            }
 
        }


Here is the xaml grid header:
<telerik:RadGridView DockPanel.Dock="Top" x:Name="grdEnterprise" ItemsSource="{Binding EnterpriseRecords}" AutoGenerateColumns="False"
                                 IsFilteringAllowed="True" ShowGroupPanel="True" SelectionMode="Extended" ShowInsertRow="True"
                                 ActionOnLostFocus="CommitEdit"  CanUserInsertRows="True" CanUserDeleteRows="True" CanUserReorderColumns="False"
                                 IsReadOnly="False" CanUserFreezeColumns="False" CanUserResizeColumns="False"
                                 Deleting="grdEnterprise_Deleting" RowIndicatorVisibility="Collapsed"
                                 RowEditEnded="grdEnterprise_RowEditEnded" EditTriggers="TextInput,CellClick"
                                 AddingNewDataItem="grdEnterprise_AddingNewDataItem" RowValidating="grdEnterprise_RowValidating"
0
Vanya Pavlova
Telerik team
answered on 10 Aug 2011, 09:50 AM
Hello Koren,

 
Would it be convenient for you to open a new support ticket and attach you application which we may use for local testing?  


Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Björn
Top achievements
Rank 1
answered on 05 Mar 2012, 04:21 PM
I'm having the same issue.
Have this been resolved? I can't find it in the public tickets.
0
Vlad
Telerik team
answered on 05 Mar 2012, 04:24 PM
Hello,

 We've not received ticket with more info about this issue. 

Greetings,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Koren
Top achievements
Rank 1
answered on 18 Jul 2012, 08:08 PM
Sorry, it is difficult to pull out the pieces to show this problem out of a bigger project. 
I am still having the same trouble with the row never displaying red that I reported earlier (error-third.png).  However, I also added some row validation on another grid and get different results.  In this grid, when I get the error, it moves the cursor to the field that is in error correctly and attaches the hint but does not change the row to red (error-first.png).  However, if I go through the record again hitting tab without changing any of the values, the second time it puts the cursor back, shows the hint and changes it to red (error-second.png).  Any way to get this to happen the first time?

I don't think I am doing anything different in this row validation than I was in the other but am getting different results.  Here is the validation:

private void grdCropProduction_RowValidating(object sender, GridViewRowValidatingEventArgs e)
        {
            if (DataContext is CropProductionViewModel)
            {
                if (e.Row != null)
                {
                    e.ValidationResults.Clear();
 
                    var _cropProdRecord = (CropProductionRecordViewModel)e.Row.Item;
                     
                    if (_cropProdRecord.TransactionCode.StartsWith("599") &&
                        (KMAR105.Records.OwnerTypeEnum)_cropProdRecord.OwnerTypeID == KMAR105.Records.OwnerTypeEnum.Owned)
                    {
                        GridViewCellValidationResult _validationResult = new GridViewCellValidationResult();
                        _validationResult.PropertyName = "TransactionCodeID";
                        _validationResult.ErrorMessage = "Only Rented Land Value should be entered in Crop Production";
                        e.ValidationResults.Add(_validationResult);
                        e.IsValid = false;
                    }
                     
                }
            }
 
        }


0
Vlad
Telerik team
answered on 24 Jul 2012, 05:48 AM
Hi,

 Can you provide more info about the grid version? 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Koren
Top achievements
Rank 1
answered on 24 Jul 2012, 12:54 PM
I just upgraded to Q2 2012.
0
Vanya Pavlova
Telerik team
answered on 25 Jul 2012, 01:54 PM
Hello Koren,




Thank you for the detailed description of this case! I believe that this issue is not a trivial one. 
Rather unfortunately without being able to reproduce the problem locally, we cannot be of much help.  
I recommend you to open a new support ticket and attach small sample application there.
In this way we would be able to provide you with an appropriate solution for your case. 




 
Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Koren
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Koren
Top achievements
Rank 1
Björn
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or