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

RadGridView gets empty when I use CollectionViesSource with different classes

5 Answers 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roman
Top achievements
Rank 1
Roman asked on 24 Nov 2010, 11:14 AM
RadGridView gets empty when I use CollectionViesSource with different inherited classes. Here is the example:

I created following window:
<Window x:Class="WpfApplication6.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=Employees}" x:Key="employees"/>
    </Window.Resources>
    <Grid>
        <telerik:RadGridView ItemsSource="{Binding Source={StaticResource employees}}" Margin="12,12,0,120" />
        <ListBox ItemsSource="{Binding Source={StaticResource employees}}" Margin="12" Height="102" VerticalAlignment="Bottom" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}" Margin="8" />
                        <TextBlock Text="{Binding Id}" Margin="8"  />
                        <TextBlock Text="{Binding Class}" Margin="8"  />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>


And codebehind:
namespace WpfApplication6
{
    public partial class App : Application
    {
        public ObservableCollection<Employee> Employees { get; set; }
 
        private void Application_Startup(object sender, StartupEventArgs e)
        {          
            Employees = new ObservableCollection<Employee>();
            Employees.Add(new Employee() { Name = "Alice", Id = 1 });
            Employees.Add(new Employee() { Name = "Bob", Id = 2 });
            Employees.Add(new Employee() { Name = "Charlie", Id = 3 });
            new MainWindow().Show();
        }      
    }
 
    public class Employee
    {
        public string Name { get; set; }
        public int Id { get; set; }
        public virtual string Class { get { return "Base"; } }
    }
 
    public class ExtendedEmployee : Employee
    {
        public override string Class { get { return "Extended"; } }
    }
}


In this example everything is ok, RadGridView and ListView displays same results. In following example everything is ok too:
Employees.Add(new ExtendedEmployee() { Name = "Alice", Id = 1 });
Employees.Add(new ExtendedEmployee() { Name = "Bob", Id = 2 });
Employees.Add(new ExtendedEmployee() { Name = "Charlie", Id = 3 });


But if I'll use mixed collection RadGridView become empty and ListBox will display correct results:
Employees.Add(new Employee() { Name = "Alice", Id = 1 });
Employees.Add(new Employee() { Name = "Bob", Id = 2 });
Employees.Add(new ExtendedEmployee() { Name = "Charlie", Id = 3 });

Screenshot is attached.
What's the problem here?

5 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 26 Nov 2010, 11:01 AM
Hi Roman,

This is really strange issue and we need some time to investigate it.
As a quick workaround you can define a CellTemplate in any of your RadGridView columns with a TextBlock bound to a particular property.

I have prepared an example for you that demonstrates this approach and also an alternative without CollectionViewSource usage that does the same thing.

Please see the attached project and let me know how this works for you.

Regards,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Roman
Top achievements
Rank 1
answered on 30 Nov 2010, 12:39 AM
Yes, that works. For now I'll stick with solution without CollectionViewSource. But It'll be good if you'll fix that issue in future updates.
0
Matthias
Top achievements
Rank 1
answered on 27 Apr 2011, 08:28 AM
Same Problem here :(

Any progress with this bug?

Regards,
Matthias
0
Matthias
Top achievements
Rank 1
answered on 27 Apr 2011, 08:41 AM
I just had a look at the provided solutions.

Using CellTemplates seems to be a fix at first glance, but sorting and grouping is not possible this way.

The second solution has no custom sorting or filtering logic.

At the moment the only solution seems to be to keep 2 collections, one with all items and one with only the filtered items.

Do you have any other/better ideas?

Regards, Matthias

0
Dimitrina
Telerik team
answered on 08 Sep 2011, 03:36 PM
Hello Matthias,

 This issue has been fixed for the Q2 2011 release of the RadControls.

Greetings,
Didie
the Telerik team

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

Tags
GridView
Asked by
Roman
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Roman
Top achievements
Rank 1
Matthias
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or