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

Row Validation on Focus Change

5 Answers 507 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 12 May 2011, 01:01 AM
Hi,

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

Sort by
0
Maya
Telerik team
answered on 12 May 2011, 04:04 PM
Hello Rob,

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 ?  

Best wishes,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Rob
Top achievements
Rank 1
answered on 18 May 2011, 02:57 AM
Hi Maya,

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
0
Maya
Telerik team
answered on 18 May 2011, 04:13 PM
Hi 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
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 Public Issue Tracking system and vote to affect the priority of the items
0
Niki
Top achievements
Rank 1
answered on 30 Aug 2013, 02:16 PM
Hi

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
0
Maya
Telerik team
answered on 02 Sep 2013, 06:37 AM
Hello 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 ?  


Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
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 >>
Tags
GridView
Asked by
Rob
Top achievements
Rank 1
Answers by
Maya
Telerik team
Rob
Top achievements
Rank 1
Niki
Top achievements
Rank 1
Share this question
or