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

Removing GridRow Via Code

4 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 05 Feb 2013, 09:55 PM
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

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 06 Feb 2013, 07:50 AM
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.

0
Ryan
Top achievements
Rank 1
answered on 06 Feb 2013, 02:58 PM
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
0
Accepted
Dimitrina
Telerik team
answered on 07 Feb 2013, 11:21 AM
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.

0
Ryan
Top achievements
Rank 1
answered on 08 Feb 2013, 02:19 PM
Didie,
Thanks a lot. That worked perfectly!

-Ryan
Tags
GridView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or