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

GridView not updating when property on item is changed

9 Answers 2054 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Odd Veibust
Top achievements
Rank 1
Odd Veibust asked on 13 Sep 2011, 07:37 PM

Hi.

I have a grid with FilterDescriptors set to a property on the items in the grid.

<telerik:RadGridView x:Name="ContractNoteGridView"
ItemsSource="{Binding ContractNotes}">
<telerik:RadGridView.FilterDescriptors>
<telerik:FilterDescriptor Member="IsEcoGenerated" Operator="IsEqualTo" Value="false" />
</telerik:RadGridView.FilterDescriptors>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Dok.Nr." DataMemberBinding="{Binding DocumentNumber}" />
<telerik:GridViewDataColumn Header="Dato" DataMemberBinding="{Binding Date, StringFormat={}{0:dd.MM.yyyy}}" />
<telerik:GridViewDataColumn Header="Eco" DataMemberBinding="{Binding IsEcoGenerated}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>

The filter is working ok when the GridView is loaded, item's are showing or not based on the property 'IsEcoGenerated'. The problem is that the GridView is not updated and removing item's if I set the property 'IsEcoGenerated' to true on one (or several) of the items. The GridViewDataColumn containing the same property does change though.

The collection used in the ItemSource (ContractNotes) is an ObservableCollection of objects of type ContracNote. ContractNote has the property IsEcoGenerated, and it implements INotifyPropertyChange , the NotifyPropertyChanged is also triggered on the setter of the property.

Can you give me a hint on what I'm doing wrong, or what I need to do to get the grid to update/refresh? The command that sets the property 'IsEcoGenerated' is a command on the ViewModel.

9 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 16 Sep 2011, 12:20 PM
Hi Odd Veibust,

Do you set the value of the 'IsEcoGenerated' property from the UI or from code behind?
 
If you change it from code behind, then the filter is not applied because a notification for a collection changed is not received by the GridView. 
 
You should inform the GridView that the collection has changed. You may do this like so:

myGridView.Items.EditItem(this.myGridView.CurrentItem);
// change the value
 myGridView.Items.CommitEdit();

Does this solve your problem?

Best wishes,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Odd Veibust
Top achievements
Rank 1
answered on 29 Sep 2011, 01:25 PM
The property is changed on a command on the viewmodel of the object, I now tried to manually fire notifypropertychange on the collectionproperty (checked that it actually did fire), but the grid still doesn't refresh.
0
tracstarr
Top achievements
Rank 1
answered on 02 Mar 2012, 04:47 PM
Did you ever figure this one out? I'm having the same issue and don't know how to get it working.
0
Steve
Top achievements
Rank 1
answered on 04 Apr 2013, 08:47 PM
I am also fighting with this.  I have an MVVM framework.  

The property (IsVisible) is being set in the Model.  The initial load of the screen appears to work but when IsVisible is changed from false to true, the row does not reappear in the gridview.  If I set IsFilteringAllowed = true and change a filter manually I can get it to appear, but this is not an ideal solution.  I need the property assignment to refresh the gridview filter. 


Edit - I noticed this thread is in the WPF section.  I'm in Silverlight, but it appears to be the exact same problem. 
0
Dimitrina
Telerik team
answered on 08 Apr 2013, 01:15 PM
Hello,

Here I have listed the options you have in order to get the GridView updated when a value is changed from the source:
1. Use the approach demonstrated in this help article.
2. Invoke a GridView.Rebind()
3. Raise a CollectionChanged event for your source collection.

I hope this will help.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Paul
Top achievements
Rank 1
Iron
Iron
commented on 10 Aug 2021, 10:20 AM

Raise a CollectionChanged event for your source collection - how?
My collection is a BindingList, I don't see how to raise a CollectionChanged event and what to put into it to tell the grid to update the visual items representing the CurrentItem.

 

 

Martin Ivanov
Telerik team
commented on 12 Aug 2021, 12:26 PM

This means that the collection bind to the ItemsSource of RadGridView should implement the INotifyCollectionChanged interface. An example for such collection is the ObservableCollection<T> class. When adding or removing items in the collection the CollectionChanged event is raised. 

It looks like the BindingList doesn't implement the INotifyCollectionChanged interface, so this option won't be available for you unless you change the collection type.

Generally speaking, in WPF is recommended to use collections that implement INotifyCollectionChanged  in order to ensure that the UI will get updated when the underlying collection is updated.

One more approach that you can use to reset the filtered items is to call the Reset() method of RadGridView's FilterDescriptors collection.

this.gridView.FilterDescriptors.Reset();

0
John
Top achievements
Rank 1
Iron
answered on 09 Sep 2016, 07:02 PM
Has anything change since this post was submitted. Is there any other way to refresh the filters once the filtered properties change? Maybe through GridViewCell.SourceChanged?
0
Dilyan Traykov
Telerik team
answered on 12 Sep 2016, 11:38 AM
Hello John,

The approaches listed by my colleague below are the only available ones with the current implementation of the control.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Martin
Top achievements
Rank 1
Veteran
answered on 22 Apr 2020, 08:56 AM

I have a similar problem, but instead of changing an item in the collection the problem is adding a new item to the collection. 

When I have FilterDecriptors added to the QueryableCollectionView my RadGridView does not update when new values are added to the list. However, if I remove the FilterDescriptors the new item is added.

Does anyone know how to fix this, so that my RadGridView does get updated when I have FilterDescriptors attached to it?

0
Martin Ivanov
Telerik team
answered on 24 Apr 2020, 08:50 AM

Hello Martin,

You can use the approaches listed in the previous post. Or alternatively, you can try to call the Reset() method of the FilterDescriptors collection of RadGridView.

radGridView.FilterDescriptors.Reset();

Regards,
Martin Ivanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
GridView
Asked by
Odd Veibust
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Odd Veibust
Top achievements
Rank 1
tracstarr
Top achievements
Rank 1
Steve
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Dilyan Traykov
Telerik team
Martin
Top achievements
Rank 1
Veteran
Martin Ivanov
Telerik team
Share this question
or