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

Problem deleting rows in a RadGridView after it's ItemsSource changes

8 Answers 449 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dustin
Top achievements
Rank 1
Dustin asked on 03 Feb 2015, 07:58 PM
Hi,

I've run into an interesting/bad behavior of the RadGridView:

I have a RadGridView (with CanUserDeleteRows="True" ) that I can change the ItemsSource based on a ComboBox.  
Initially, I am able to delete rows.  However, after I switch the ItemsSource, I am unable to delete rows *unless I first put the grid manually into edit mode and back again*.   My desired behavior is for the grid to behave the same regardless of whether or not the grid's ItemsSource has changed.

I have tried to attach an example of this behavior to this message, but I get an error message saying:

"The selected file(s) cannot be attached because it may exceed the maximum attachment size (2 MB) or is from not allowed type (allowed: .gif, .jpg, .jpeg, .png)."

The file I'm attempting to upload ends with .zip and is 8.45kb in size....

Please let me know:
1) How do I attach a 8.45kb .zip file?
2) How do I get the behavior I require from the RadGridView?

Thanks,
Dustin

8 Answers, 1 is accepted

Sort by
0
Dustin
Top achievements
Rank 1
answered on 03 Feb 2015, 08:12 PM
Here is the .zip file, shared from my google drive:

https://drive.google.com/file/d/0Bzs8aZNn2PX_Wkp0MWdZeE5FRjQ/view?usp=sharing

To reproduce the behavior I mentioned above using my example:

Change the selection in the ComboBox and try to delete a row in the RadGridView by selecting a row and hitting the "delete" key (for me, it fails to delete the row). Now, double click inside a cell of the RadGridView to put it into edit mode and then hit the "esc" key to get out of edit mode.  Try deleting a row now (for me, it successfully now deletes the row).
0
Dimitrina
Telerik team
answered on 06 Feb 2015, 03:27 PM
Hi Dustin,

I checked the demo solution and I was indeed able to reproduce the issue. It seems that in the problematic cases RadGridView loses focus and that is why the deletion cannot be performed. Once I click on the row to focus it, it works fine. 
After performing some tests, additionally focusing the control helps. You need to subscribe for the SelectionChanged event of ComboBox and then execute some additional logic as suggested below:
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    grid.Focus();
}

Let me know how this works for you.

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
Dustin
Top achievements
Rank 1
answered on 06 Feb 2015, 03:56 PM
"It seems that in the problematic cases RadGridView loses focus and that is why the deletion cannot be performed. Once I click on the row to focus it, it works fine. "

This is not exactly my experience.  

Repro steps in the demo example:

-Open the test app.  "Things 1" should already be selected in the ComboBox.
-Select the first row of the RadGrid by clicking the left-most grey box of the row (I'm not sure what this column is called, but it's where the row status shows up, say if it's in edit-mode, etc).  Clicking this box seems to select the row (the row is highlighted). 
-Hit 'Del' key.  The row is deleted.
-Now, with the combo-box, switch to "Things 2".
-Select the first row of the RadGrid by clicking the left-most grey box of the row.
-Hit the 'Del' key.  The row will *not* be deleted, unless I select an actual cell of the row. So, even though I've clicked on the grid, and selected a row, the RadGrid is not in focus??

I think it's a bit incorrect to say that only clicking on a row is necessary to allow row deletions.  Instead, it seems that there's a bug in the RadGridView, such that, even though I have selected a row (by clicking that left-most grey box), the RadGridView isn't coming into focus.  The work-around you showed *does* work in this particular vastly simplified case, but it's not really acceptable for my actual application, because I don't want to shift focus to my grid, unless the user actually clicks on the grid!  I guess I could work-up a hacky solution to focus on the grid based on any mouse-click it receives?  Not sure yet, but it's a shame to have to go through each and every grid in my application (there are many of them) and add this hack...













0
Dustin
Top achievements
Rank 1
answered on 06 Feb 2015, 05:01 PM
For now, I am using an attached property to work around this bug:

public class RadGridViewSetFocusHack
  {
    public static bool GetEnabled(DependencyObject obj)
    {
      return (bool)obj.GetValue(EnabledProperty);
    }
 
    public static void SetEnabled(DependencyObject obj, bool value)
    {
      obj.SetValue(EnabledProperty, value);
    }
 
    static void OnSelectionChanged(object sender, EventArgs e)
    {
      var ue = sender as FrameworkElement;
      if (ue == null) return;
      if (ue.Focusable)
        ue.Focus();
    }
 
    private static void Unloaded(object sender, RoutedEventArgs e)
    {
      var ue = sender as DataControl;
      if (ue == null) return;
 
      ue.Unloaded -= Unloaded;
      ue.SelectionChanged -= OnSelectionChanged;
    }
 
    public static readonly DependencyProperty EnabledProperty =
        DependencyProperty.RegisterAttached("Enabled", typeof(bool),
 
        typeof(EnterKeyTraversal), new UIPropertyMetadata(false, EnabledChanged));
 
    static void EnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
      var ue = d as DataControl;
      if (ue == null) return;
 
      if ((bool)e.NewValue)
      {
        ue.Unloaded += Unloaded;
        ue.SelectionChanged += OnSelectionChanged;
      }
      else
      {
        ue.SelectionChanged -= OnSelectionChanged;
      }
    }
  }

Used in xml:

<telerik:RadGridView ItemsSource="{Binding}" RadGridViewSetFocusHack.Enabled="True" />

0
Dustin
Top achievements
Rank 1
answered on 06 Feb 2015, 05:03 PM
there's a slight mistake in the above code, but I can't seem to find how to edit my post...sorry.
0
Dimitrina
Telerik team
answered on 06 Feb 2015, 05:08 PM
Hi,

This seems to be indeed a bug as proved by the provided use case. We are going to further investigate it.

Please excuse us for the 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
Jose
Top achievements
Rank 1
answered on 15 Oct 2015, 04:10 PM
Hello! We are experiencing the same issue described in this thread. Has this bug been fixed? 
0
Stefan
Telerik team
answered on 20 Oct 2015, 01:08 PM
Hi Jose,

The bug has already been fixed. Can you please try updating your binaries to the latest version and let me know whether you are experiencing the issue anymore?

Best Regards,
Stefan
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Dustin
Top achievements
Rank 1
Answers by
Dustin
Top achievements
Rank 1
Dimitrina
Telerik team
Jose
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or