Flaw with arrow navigation and editriggers=none

4 posts, 0 answers
  1. Fredrik
    Fredrik avatar
    58 posts
    Member since:
    Mar 2013

    Posted 06 Sep 2014 Link to this post

    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>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Sep 2014 Link to this post

    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.
     
  3. DevCraft banner
  4. Fredrik
    Fredrik avatar
    58 posts
    Member since:
    Mar 2013

    Posted 08 Sep 2014 in reply to Dimitrina Link to this post

    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");
                    }

                }
            }

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Sep 2014 Link to this post

    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.
     
Back to Top