This question is locked. New answers and comments are not allowed.
Hi,
When I have a gridview that is bound to the selectedItem of another gridview and a filterdescriptor then this filter descriptor gets lost when refetching data.
Steps to reproduce in my test application:
- Press the fetch button
- Select the first item and see that the righthand side grid has 1 row
- Press the fetch button
- Select the first item again and see that the righthand side grid has 3 rows
I have the following xaml:
<Window x:Class="TelerikGrid.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow" WindowStartupLocation="CenterScreen" Height="600" Width="800"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <StackPanel> <Button Content="Fetch" Click="FetchClick"/> </StackPanel> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="10" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <telerik:RadGridView x:Name="UserListBox" AutoGenerateColumns="False" ItemsSource="{Binding Items}"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Caption}" /> </telerik:RadGridView.Columns> </telerik:RadGridView> <telerik:RadGridView Grid.Column="2" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=UserListBox, Path=SelectedItem.Children}"> <telerik:RadGridView.FilterDescriptors> <telerik:FilterDescriptor Member="IsVisible" Operator="IsEqualTo" Value="True" /> </telerik:RadGridView.FilterDescriptors> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Caption}" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding IsVisible}" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid> </Grid></Window>And the following code behind:
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace TelerikGrid{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; } public ObservableCollection<Item> Items { get { return (ObservableCollection<Item>)GetValue(ItemsProperty); } set { SetValue(ItemsProperty, value); } } public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(ObservableCollection<Item>), typeof(MainWindow), new PropertyMetadata(null)); private void FetchClick(object sender, RoutedEventArgs e) { Items = new ObservableCollection<Item>(); Item item1 = new Item() { Caption = "Item 1" }; Item item2 = new Item() { Caption = "Item 2" }; item1.Children.Add(new SubItem() { Caption = "SubItem 1", IsVisible = true }); item1.Children.Add(new SubItem() { Caption = "SubItem 2", IsVisible = false }); item1.Children.Add(new SubItem() { Caption = "SubItem 3", IsVisible = false }); Items.Add(item1); Items.Add(item2); } } public class Item : DependencyObject { public string Caption { get; set; } public ObservableCollection<SubItem> Children { get { return (ObservableCollection<SubItem>)GetValue(ChildrenProperty); } set { SetValue(ChildrenProperty, value); } } public static readonly DependencyProperty ChildrenProperty = DependencyProperty.Register("Children", typeof(ObservableCollection<SubItem>), typeof(MainWindow), new PropertyMetadata(null)); public Item() { Children = new ObservableCollection<SubItem>(); } } public class SubItem : DependencyObject { public string Caption { get; set; } public bool IsVisible { get; set; } }}