Removing GridRow Via Code

5 posts, 1 answers
  1. Ryan
    Ryan avatar
    3 posts
    Member since:
    Oct 2012

    Posted 05 Feb 2013 Link to this post

    Hi,
    I'm creating a predetermined list of GridView's as controls in a WPF ItemsControl control, and am trying to remove rows via the ViewModel code. I am able to reference the ItemsControl binding, and when I try to delete a specified row via MyGrid.Items.Remove(knownRow), it fails (I also tried adding MyGrid.Items.Refresh() after it). I walked through the code, and found that the property MyGrid.Items.CanRemove is set to false. It's a get only property, so changing it isn't an option.

    When creating the grid dynamically, I also tried setting the following properties:

    grid.CanUserDeleteRows = true;
    grid.IsReadOnly = false;

    How do I go about removing rows from the grid?

    Thanks,
    Ryan
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Feb 2013 Link to this post

    Hello Ryan,

    May I ask you what is your bound collection? Does it allow a remove itself? 

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Ryan
    Ryan avatar
    3 posts
    Member since:
    Oct 2012

    Posted 06 Feb 2013 Link to this post

    Hi Didie,
    Thanks for responding. Yes it's just a standard .net DataTable. I instantiate a new table, fill it with the required data, and then return that new DataTable and set my grid view's itemsSource to it.

    -Ryan
  4. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Feb 2013 Link to this post

    Hi Ryan,

    Please set the ItemsSource to be the DefaultView of the DataTable and you will be able to remove items. 

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Ryan
    Ryan avatar
    3 posts
    Member since:
    Oct 2012

    Posted 08 Feb 2013 Link to this post

    Didie,
    Thanks a lot. That worked perfectly!

    -Ryan
Back to Top