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

Flaw with arrow navigation and editriggers=none

3 Answers 9 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fredrik
Top achievements
Rank 2
Fredrik asked on 06 Sep 2014, 01:30 PM
Hello, i have a radgridview where you are supposed insert new rows and read data.
the user should not be able to edit data that has been added.

the problem is when the user  press "add new row" and during the typing of a new row he can press the up and down arrow keys and navigate to the other row items whitch he shouldnt be allowed to edit.

please help

see grid markup bellow:


                            <telerikGridView:RadGridView Margin="12,0,0,0" Grid.Row="1" Grid.Column="1" x:Name="RadGridView6"
                                                                 MaxHeight="115" 
                                                                 RowIndicatorVisibility="Collapsed" 
                                                                 CanUserFreezeColumns="False" 
                                                                 ItemsSource="{Binding JournalItems}" SelectionMode="Single" CanUserSelect="True"  EditTriggers="None" ShowGroupPanel="False"  CanUserInsertRows="True" ShowInsertRow="{Binding CanType}" ShowColumnHeaders="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                                                 AutoGenerateColumns="False">
                                <telerikGridView:RadGridView.Columns>
                                    <telerikGridView:GridViewDataColumn Header="{Binding LocalizedStrings.view_kundeinfo_journal_dato, Source={StaticResource LocalizedStrings}}" 
                                                                                DataMemberBinding="{Binding p_Dato,Converter={StaticResource DateTimeConverter}}" TextAlignment="Left" />
                                    <telerikGridView:GridViewDataColumn Header="{Binding LocalizedStrings.view_kundeinfo_journal_text, Source={StaticResource LocalizedStrings}}" Width="*" TextWrapping="Wrap" 
                                                                                DataMemberBinding="{Binding p_Tekst}"  >
                                                                        
                                                                        
                                    </telerikGridView:GridViewDataColumn>
  
                                </telerikGridView:RadGridView.Columns>

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 08 Sep 2014, 11:03 AM
Hello,

You can redefine how the GridView internally handles the "Up" and "Down" navigation keys, creating your own custom keyboard provider. 
Please refer to our online documentation for further details.
 
In your particular case, you can extend the ProvideCommandsForKey method as follows:
public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
    List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
    
    if (key == Key.Up)
    {
        commandsToExecute.Remove(RadGridViewCommands.MoveUp);
    }
    if (key == Key.Down)
    {
        commandsToExecute.Remove(RadGridViewCommands.MoveDown);
    }
    return commandsToExecute;
}

In case you would like to stop the arrow navigation only while the user is adding a new item, then you can add an additional if statement.
For example:
public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
    List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
    if (key == Key.Up)
    {
        if (parentGrid.Items.IsAddingNew)
        {
            commandsToExecute.Remove(RadGridViewCommands.MoveUp);
        }
    }
    if (key == Key.Down)
    {
        if (parentGrid.Items.IsAddingNew)
        {
            commandsToExecute.Remove(RadGridViewCommands.MoveDown);
        }
    }
    return commandsToExecute;
}

I hope this helps.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Fredrik
Top achievements
Rank 2
answered on 08 Sep 2014, 11:17 AM

Hello, and thanks for your sollution.
I still think its strange that there is no property to explicitly prohibit editing of existing raws.

I choosed to solve it with using the IsReadOnlyBinding since I found this solution a bit more elegant
I have a property in my object return the entitystate of my object and then determine if the entity should be readable or not.


 <telerikGridView:GridViewDataColumn Header="{Binding LocalizedStrings.view_kundeinfo_journal_text, Source={StaticResource LocalizedStrings}}" Width="*" TextWrapping="Wrap" IsReadOnlyBinding="{Binding ReadOnly}"
                                                                                DataMemberBinding="{Binding p_Tekst}" >

 public bool ReadOnly
        {
            get
            {
                if(EntityAspect.EntityState == IdeaBlade.EntityModel.EntityState.Unchanged)
                {
                    return true;
                }
                else if (EntityAspect.EntityState == IdeaBlade.EntityModel.EntityState.Added)
                {
                    return false;
                }
                else
                {
                    throw new Exception("Unknown Entitystate");
                }

            }
        }

0
Dimitrina
Telerik team
answered on 08 Sep 2014, 11:26 AM
Hi,

This seems to be a better solution in your case. You can also take a look at the respective article on Read Only Rows and Cells for an additional reference.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Fredrik
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
Fredrik
Top achievements
Rank 2
Share this question
or