I have been working with the validation on my RadGridView. It works a little too well. I don't want to use cell validation but row validation is occurring with every cell edit. I would like to see something like the ValidatesOnDataErrors property contain an option for OnRowFocusLost or similar meaningful option.
I have looked around but in this case cannot seem to find a way of achieving what I want. How do you get the RadGridView to do RowValidating only when the focus is about to go to another row?
Thanks,
Rob
5 Answers, 1 is accepted
Basically, the RowValidating event will be fired on committing the editing when you are trying to go to another row. The CellValidating and CellValidated events will be fired when the edited cell is losing the focus. You may take a look at our online documentation for further reference on the validating events and the way a validation can be performed.
Still, in order to provide you with more accurate solution, I would need slightly more details about the exact scenario that you want to accomplish. How do you expect your RadGridView to behave ?
Maya
the Telerik team

Sorry for the delayed response. I have been home sick. :(
My employer would like to have a row validation checked only when they leave the row. However, I realised that because they also were starting from the left most column and typing some data then hitting the Enter key to move to the next column of the same row it was causing strange behaviour.
I have informed my employer that hitting the Tab key would be more natural to move to the next column but they are firm on making the Enter key do this.
When they are in the 2nd or 3rd last column (depending on whether Debit or Credit value entered) and hit Enter, the behaviour they wish to see the RadGridView exhibit is to create a new line, give the newline focus and perform validation on the row that has just been vacated (lost focus).
I have managed to produce somewhat the validation required but it is not quite right. I'll include the XAML if it helps.
<
telerik:RadGridView
x:Name
=
"grid1"
Grid.Row
=
"1"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"False"
RowIndicatorVisibility
=
"Collapsed"
CanUserInsertRows
=
"False"
EditTriggers
=
"CellClick"
ItemsSource
=
"{Binding StatementLines}"
IsReadOnly
=
"{Binding IsReadOnly}"
aps:SingleEventCommand.RoutedEventName
=
"CellEditEnded"
aps:SingleEventCommand.CommandParameter
=
"{Binding ElementName=grid1, Path=CurrentCell.Column.UniqueName}"
aps:SingleEventCommand.TheCommandToRun
=
"{Binding CellEditEndedCommand}"
RowValidating
=
"grid1_RowValidating"
ValidatesOnDataErrors
=
"InEditMode"
abs:RadGridViewKeyboardBehaviour.IsEnabled
=
"True"
abs:RadGridViewKeyboardBehaviour.EnterDirection
=
"MoveNext"
>
<
telerik:RadGridView.Resources
>
<
Style
x:Key
=
"ComboEditorStyle"
TargetType
=
"telerik:RadComboBox"
>
<
Setter
Property
=
"IsDropDownOpen"
Value
=
"True"
/>
</
Style
>
</
telerik:RadGridView.Resources
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Account"
DataMemberBinding
=
"{Binding TransactionGLAccount.AccountCode}"
IsReadOnly
=
"{Binding IsReadOnly}"
Width
=
"100"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
local:EntityLookupView
GridType
=
"{x:Static Member=util:LookupGridType.FinancialsTransaction}"
Entity="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadGridView}},
Path
=
SelectedItem
.TransactionGLAccount,
Mode
=
TwoWay
}"
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadGridView}},
Path
=
SelectedItem
.TransactionGLAccount.AccountCode}"
ValidateEntityCode
=
"True"
FocusNow
=
"False"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewComboBoxColumn
Header
=
"Branch"
ItemsSource
=
"{Binding Branches}"
Width
=
"Auto"
MinWidth
=
"50"
DataMemberBinding
=
"{Binding BranchID}"
DisplayMemberPath
=
"Description"
IsReadOnly
=
"{Binding IsReadOnly}"
SelectedValueMemberPath
=
"LookupID"
EditorStyle
=
"{StaticResource ComboEditorStyle}"
IsVisible
=
"{Binding CurrentApplicationSettingContext.Financials_BranchesActive}"
/>
<
telerik:GridViewComboBoxColumn
Header
=
"Tax"
ItemsSource
=
"{Binding TaxGroups}"
Width
=
"Auto"
MinWidth
=
"50"
DataMemberBinding
=
"{Binding TaxGroupID}"
DisplayMemberPath
=
"TaxGroup"
IsReadOnly
=
"{Binding IsReadOnly}"
SelectedValueMemberPath
=
"TaxGroupID"
EditorStyle
=
"{StaticResource ComboEditorStyle}"
/>
<
telerik:GridViewDataColumn
Header
=
"Description"
DataMemberBinding
=
"{Binding Description, Mode=TwoWay}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Debit}"
Width
=
"100"
TextAlignment
=
"Right"
IsVisible
=
"{Binding ShowWithdrawals}"
DataFormatString
=
"{Binding CurrentApplicationSettingContext.GridCurrencyFormat}"
>
<
telerik:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Withdrawals (Payments)"
TextWrapping
=
"Wrap"
TextAlignment
=
"Center"
/>
</
telerik:GridViewDataColumn.Header
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Credit}"
Width
=
"100"
TextAlignment
=
"Right"
IsVisible
=
"{Binding ShowDeposits}"
DataFormatString
=
"{Binding CurrentApplicationSettingContext.GridCurrencyFormat}"
>
<
telerik:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Deposits (Receipts)"
TextWrapping
=
"Wrap"
TextAlignment
=
"Center"
/>
</
telerik:GridViewDataColumn.Header
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Regards,
Rob
I sorry to hear that you have been sick, I do hope you are much better now.
As for the current issue, you may do the following:
public MainWindow()
{
InitializeComponent();
this.clubsGrid.AddingNewDataItem+=new EventHandler<
Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs
>(clubsGrid_AddingNewDataItem);
this.clubsGrid.AddHandler(RadGridView.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);//.KeyDown += new KeyEventHandler(clubsGrid_KeyDown);
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var grid = sender as RadGridView;
Club selectedItem = grid.SelectedItem as Club;
int selectedIndex = this.clubsGrid.Items.IndexOf(selectedItem);
if ((selectedIndex == this.clubsGrid.Items.Count - 1))
{
grid.BeginInsert();
grid.CurrentColumn = grid.Columns[0];
}
else
{
e.Handled = true;
}
}
}
private void clubsGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
e.NewObject = new Club();
}
Best wishes,
Maya
the Telerik team

Can anyone please advise how to do this with the RadGridView in 2013?
Some of the properties don't exist any more (e.g. grid.selecteditem), and I'm just learning from my first grid...
Many thanks!
Niki
We did not remove SelectedItem property. You can check out our online documentation for more information. Could you clarify what the error you get is ?
Maya
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>