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

UI crashes when group descriptor added twice or nulled from a template column.

1 Answer 47 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Thomas
Top achievements
Rank 1
Thomas asked on 28 Oct 2013, 11:04 PM
I have found that when using DataGridTemplateColumn types, an assigned group descriptor can be added twice.  The second add crashes the UI thread. 

If I try to set the column group descriptor to null, inside of the collections changing event for the grid group descriptors collection, the UI crashes as well.

I have a small project that will reproduce the problem, but I see I am unable to attach it.  The code excerpts are below.

Thanks,
Tom

Code:

public MainPage()

{

this.InitializeComponent();

this.DataGrid.ItemsSource = new List<Data>

{

new Data { Name = "Mario", Hobby = "Boxing", Age = 22 },

new Data { Name = "Smith", Hobby = "Skating", Age = 23 },

new Data { Name = "Maya", Hobby = "Swimming", Age = 24 },

new Data { Name = "Sonya", Hobby = "Jogging", Age = 21 },

new Data { Name = "Tom", Hobby = "Jogging", Age = 25 },

new Data { Name = "Mario", Hobby = "Skating", Age = 22 },

new Data { Name = "Smith", Hobby = "Skating", Age = 25 },

new Data { Name = "Peter", Hobby = "Boxing", Age = 22 },

new Data { Name = "Lorenzo", Hobby = "Boxing", Age = 24 }

};

this.DataGrid.GroupDescriptors.CollectionChanged += GroupDescriptors_CollectionChanged;

}

void GroupDescriptors_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

{

DataGridTemplateColumn ageColumn = FindAgeColumn() as DataGridTemplateColumn;

if (ageColumn == null) return;

if (e.NewItems != null)

{

// This line of code blows UI up

//ageColumn.GroupDescriptor = null;

}

if (e.OldItems != null)

{

ageColumn.GroupDescriptor = e.OldItems[0] as GroupDescriptorBase;

}

}

DataGridColumn FindAgeColumn()

{

foreach (DataGridColumn column in this.DataGrid.Columns)

{

if (column.Header.ToString() == "Age")

return column;

}

return null;

}


<telerikGrid:RadDataGrid x:Name="DataGrid" AutoGenerateColumns="False" >

<telerikGrid:RadDataGrid.GroupDescriptors>

<telerikGrid:DelegateGroupDescriptor x:Name="ageGroupDescriptor" >

<telerikGrid:DelegateGroupDescriptor.KeyLookup>

<local:CustomIKeyLookup/>

</telerikGrid:DelegateGroupDescriptor.KeyLookup>

</telerikGrid:DelegateGroupDescriptor>

</telerikGrid:RadDataGrid.GroupDescriptors>

<telerikGrid:RadDataGrid.Columns>

<telerikGrid:DataGridTemplateColumn Header="Name">

<telerikGrid:DataGridTemplateColumn.CellContentTemplate>

<DataTemplate>

<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

</DataTemplate>

</telerikGrid:DataGridTemplateColumn.CellContentTemplate>

</telerikGrid:DataGridTemplateColumn>

<telerikGrid:DataGridTemplateColumn Header="Hobby">

<telerikGrid:DataGridTemplateColumn.CellContentTemplate>

<DataTemplate>

<TextBlock Text="{Binding Hobby}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

</DataTemplate>

</telerikGrid:DataGridTemplateColumn.CellContentTemplate>

</telerikGrid:DataGridTemplateColumn>

<telerikGrid:DataGridTemplateColumn Header="Age" x:Name="ageColumn">

<telerikGrid:DataGridTemplateColumn.CellContentTemplate>

<DataTemplate>

<TextBlock Text="{Binding Age}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

</DataTemplate>

</telerikGrid:DataGridTemplateColumn.CellContentTemplate>

</telerikGrid:DataGridTemplateColumn>

</telerikGrid:RadDataGrid.Columns>

</telerikGrid:RadDataGrid>


public class CustomIKeyLookup : IKeyLookup

{

public object GetKey(object instance)

{

return (instance as Data).Age;

}

}


1 Answer, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 29 Oct 2013, 01:19 PM
Hi Thomas,

Thank you for contacting us.

We have to admit that there is a bug in the RadDataGrid control when you add a group descriptor to a DataGridTemplateColumn and the user tries to group twice by this column. I have redirected this issue to our development team and they will do their best to fix it for the next service pack planned for the beginning of November.

According to the code snippet you have sent, in the GroupDescriptors_CollectionChanged method when you try to set the ageColumn.GroupDescriptor to null, the DataGrid.GroupDescriptors collection
contains this descriptor. What happens is that you try to change the collection during the CollectionChanged event which throws an exception.

Thank you for your valuable feedback and feel free to contact us if you have any other questions. I have also updated your Telerik points as a token of gratitude for bringing this issue to our attention.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Grid for XAML
Asked by
Thomas
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Share this question
or