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

9 posts, 0 answers
  1. Dustin
    Dustin avatar
    10 posts
    Member since:
    Sep 2014

    Posted 03 Feb 2015 Link to this post

    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
  2. Dustin
    Dustin avatar
    10 posts
    Member since:
    Sep 2014

    Posted 03 Feb 2015 in reply to Dustin Link to this post

    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).
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Feb 2015 Link to this post

    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.

     
  5. Dustin
    Dustin avatar
    10 posts
    Member since:
    Sep 2014

    Posted 06 Feb 2015 in reply to Dimitrina Link to this post

    "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...













  6. Dustin
    Dustin avatar
    10 posts
    Member since:
    Sep 2014

    Posted 06 Feb 2015 in reply to Dustin Link to this post

    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" />

  7. Dustin
    Dustin avatar
    10 posts
    Member since:
    Sep 2014

    Posted 06 Feb 2015 in reply to Dustin Link to this post

    there's a slight mistake in the above code, but I can't seem to find how to edit my post...sorry.
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Feb 2015 Link to this post

    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.

     
  9. Jose
    Jose avatar
    2 posts
    Member since:
    Aug 2014

    Posted 15 Oct 2015 in reply to Dimitrina Link to this post

    Hello! We are experiencing the same issue described in this thread. Has this bug been fixed? 
  10. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 20 Oct 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready