Question

I am deleting a row in the grid and when the user clicks the delete button the property IsDeleted in the collection is changed to true and so the filter in .xaml page binds the property to the telerik grid.

//Code

Filter:

 <telerik:RadGridView.FilterDescriptors>
           <telerik:FilterDescriptor Member="IsDeleted" Operator="IsEqualTo" Value="False"/>
 </telerik:RadGridView.FilterDescriptors>

ViewModel:

 if (this.IsNPISItemSelected && MessageBox.Show("Are you sure that you want to delete the selected npis item?", "Delete NPIS Item", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    this.SelectedNPISItem.IsDeleted = true;


                }

Binding GridView:

 <telerik:RadGridView x:Name="grdNPISItem" ItemsSource="{Binding NPISItemsCollection, Mode=TwoWay}" AutoGenerateColumns="False" SelectedItem="{Binding SelectedNPISItem, Mode=TwoWay, Source={StaticResource NPISViewModel}}" 
                                HorizontalAlignment="Stretch" telerik:StyleManager.Theme="Windows8"
                                Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}, Path=ActualWidth, Converter={StaticResource PercentageConverter}, ConverterParameter=0.98}" 
                                GridLinesVisibility="Both">

But now, when i delete the row its still showing. The thing is if the property is false the row should not be shown in the grid.

I guess the grid is not refreshing.

Where i'm wrong?

Was it helpful?

Solution

Apparently, RadGridView does not treat property change as reason to update filters. You can test and see that if you update the value via grid itself, then filtering takes place normally because proper grid edit procedure is done.

Simple solution can be to raise some custom event in ViewModel to notify the View that filters should be updated:

grdNPISItem.FilterDescriptors.Reset();

But I think that it could be better to move that logic to ViewModel and make a collection with just existing values and bind it to the grid:

 public IEnumerable<NPISItem> ExistingNPISItemsCollection
  {
     get
     {
        return NPISItemsCollection == null 
                   ? Enumerable.Empty<NPISItem>() 
                   : NPISItemsCollection .Where(d => !d.IsDeleted);
     }
  }

Then when you change IsDeleted property you just call PropertyChanged for this collection and grid will pick it up. This also allows to keep grid column filtering so user can work with shown items as he likes.

The null check here is in case collection`s not initialized yet when binding takes place, so you can either remove it if you don`t need it or call PropertyChanged for this collection in NPISItemsCollection setter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top