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

Disabled items can be selected with shift-click

9 Answers 314 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 24 Sep 2014, 02:36 PM
I have a RadGridView with SelectionMode="Extended". The bound items have an IsEnabled property, and the rows are enabled or disabled using this property by modifying the style as follows:

    <uxt:UxtWindow.Resources>
        <Style TargetType="{x:Type telerik:GridViewRow}" BasedOn="{StaticResource GridViewRowStyle}">
            <Setter Property="IsEnabled" Value="{Binding Path=IsEnabled}"/>
        </Style>
    </uxt:UxtWindow.Resources>

This is fine in so far as the disabled rows are correctly displayed greyed-out, if I click on a disabled row it is not selected and if I click on a disabled row with Control held down it is also not selected. The problem is that if I click on a row above a disabled row, hold down Shift and then click on a row below the disabled row, all the rows between the two clicked-on rows are selected including the disabled row.

Is this a bug and is there anything I can do about it?

9 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 26 Sep 2014, 11:36 AM
Hi Dave,

In order to achieve the desired functionality, you will need to modify the default commands that will be executed as the user extended select. You can re-define the behavior when pressing the Down arrow key with holding the Shift key down by creating your own custom keyboard provider. You can check the Keyboard Command Provider help article for a reference. Moreover, you can check this GitHub example - it demonstrates how to redefine the default KeyboardProvider.

The specific code you need to implement is:
public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
    List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
 
    if (key == Key.Down && KeyboardModifiers.IsShiftDown)
    {
        if (grid.ParentRow != null)
        {
          var parentRow = grid.ParentRow.Item as Club;
          
          if (parentRow.IsEnabled)
          {
             commandsToExecute.RemoveAt(1);
          }
       }
    }         
    return commandsToExecute;
 }
}

As a side note - Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our SDK Samples Browser. You can also use it to review the examples.

Let me know how this works for you.

Regards,
Dimitrina
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
Dave
Top achievements
Rank 1
answered on 29 Sep 2014, 12:26 PM
Hi DimitrIna
Thanks for that. Unfortunately I can't get it to work as grid.ParentRow always seems to be null. Can you explain this?

Also, this does not actually solve the entire problem. There are three situations (that I have identified, there may be more) where the RadGridView fails to perform correctly:
1. When shift is held down while moving the cursor up or down using the cursor keys
2. When shift is held down and a row is clicked with the mouse
3. When Ctrl-A (select all) is pressed

Your solution would solve case 1 (if grid.Parent row were not null);
It does not solve Case 3 - I have tried to trap Ctrl-A using your method but ProvideCommandsForKey() is not executed at all when Ctrl-A is pressed;
It does not solve Case 2 at all as it is a keyboard handler, and case 3 obviously requires mouse click handling.

Please could you provide workarounds for all three of these bugs.

Thanks

Dave
0
Accepted
Yoan
Telerik team
answered on 30 Sep 2014, 04:12 PM
Hi Dave,

I would suggest you slightly different approach - you can deselect all items which have IsEnabled = true in GridView's SelectionChanged event. Please check the attached sample project for a reference.

Regards,
Yoan
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
Dave
Top achievements
Rank 1
answered on 02 Oct 2014, 04:51 PM
OK. I can use that as a work-around, but this must surely be a bug. Hopefully it will be fixed in a future release.
0
Dave
Top achievements
Rank 1
answered on 03 Oct 2014, 09:02 AM
This is not a complete solution, because although it removes the item from the SelectedItems collection, it does not (and cannot) remove it from the AddedItems collection in the SelectionChangedEventArgs. We use another subscriber to SelectionChanged (in a WPF Behaviour to allow the SelectedItems to be bound) and this will still see the disabled item in the AddedItems collection.
0
Accepted
Dimitrina
Telerik team
answered on 07 Oct 2014, 11:30 AM
Hello Dave,

You are right and this is indeed not something the end user would expect. That is why I logged your report as an issue into our internal system.

You say you use another subscriber for the SelectionChanged event. The selected and then deselected items are available in the e.AddedItems collection as they are already extended selected. It is the internal logic of RadGridView that should be modified so that no disabled items are added to the e.AddedItems at all. For the time being, is it an option for you to use the SelectedItems collection instead? 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dave
Top achievements
Rank 1
answered on 07 Oct 2014, 12:41 PM
Hi Dimitrina,
Thanks for logging this as an issue.
Yes I could, but I don't want to modify our SelectedItemsChangedBehaviour which is in a utilities library and is designed to work with ListView as well as RadListView. I have worked around the problem in the actual code for the moment.
If I could be notified as and when a fix is released that would be helpful.
Thanks for your help.
Dave
0
Accepted
Dimitrina
Telerik team
answered on 07 Oct 2014, 12:56 PM
Hi Dave,

You can find a link to the story in our Feedback Portal:
Disabled items can be selected with shift-click.

There, you can vote for it and you can also subscribe for following it. In that way you will be notified once there is any change in its status.

I apologize for this inconvenience.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Maya
Telerik team
answered on 09 Mar 2015, 01:00 PM
Hello Dave,

We investigated the issue thoroughly and it is actually not a bug. I posted more info in the related feedback item. I do hope the suggested solutions here are appropriate for you or else, you can also right us back if you need any assistance. 


Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Dave
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Dave
Top achievements
Rank 1
Yoan
Telerik team
Maya
Telerik team
Share this question
or