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!
thanks!
9 Answers, 1 is accepted
0
Hello Koren,
Vanya Pavlova
the Telerik team
May post more info about how the grid is bound to and the source-code behind RowValidating event handler?
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:
Here is the xaml grid header:
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
Hello Koren,
Vanya Pavlova
the Telerik team
Would it be convenient for you to open a new support ticket and attach you application which we may use for local testing?
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.
Have this been resolved? I can't find it in the public tickets.
0
Hello,
Vlad
the Telerik team
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:
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
Hi,
Vlad
the Telerik team
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
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.
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.