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

wsod when changing a datacontext if the gridview has a grouped column

4 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 23 Apr 2012, 11:22 PM
I am using a gridview to display an entitycollection, if i remove an item from the entitycollection and re bind the datacontext it works fine, unless the gridview has a grouped column in which case I get the WSOD, or the following stacktrace on my development machine, any ideas?

System.Reflection.TargetInvocationException was unhandled by user code
  Message=Exception has been thrown by the target of an invocation.
  StackTrace:
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Delegate.DynamicInvokeImpl(Object[] args)
       at System.Delegate.DynamicInvoke(Object[] args)
       at ScheduledSessionsxaml.BindingOperation(Object BindingState, Int32 , Action )
  InnerException: System.ArgumentException
       Message=Value does not fall within the expected range.
       StackTrace:
            at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
            at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
            at System.Windows.UIElement.UpdateLayout()
            at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
            at Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
            at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
            at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
            at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
            at System.Windows.Data.BindingExpression.SendDataToTarget()
            at System.Windows.Data.BindingExpression.SourceAcquired()
            at System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass4.<BreakOnSharedType>b__3()
       InnerException:


One option might be to capture the grouped column state, remove it and reapply after the datacontext is updated

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 24 Apr 2012, 09:14 AM
Hi Jeremy,

Can you give some hint on how we can reproduce the issue locally . I am sure we can think of some workaround once we have a repro of the issue.

Kind regards,
Pavel Pavlov
the Telerik team

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

0
Jeremy
Top achievements
Rank 1
answered on 24 Apr 2012, 10:08 AM
Hi Thanks for looking at this,

My data is an entitycollection derived from a standard domaindatasource, when changes are submitted or dataloaded it fires a trigger which reapplys the datacontext, this works fine if the grid view does not have a grouped column.

My xaml looks like this
<telerik:RadGridView x:Name="dgdScheduled" RowDetailsVisibilityMode="VisibleWhenSelected" telerik:StyleManager.Theme="Metro"  Margin="0" BorderThickness="0" GridLinesVisibility="None" IsReadOnly="True" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" ActionOnLostFocus="None" CanUserInsertRows="False" CanUserDeleteRows="False" ItemsSource="{Binding}" BorderBrush="{x:Null}" GroupRowStyle="{StaticResource Metro_GridViewGroupRowStyle1}" EditTriggers="None" >
    <telerik:RadGridView.Columns
                <telerik:GridViewDataColumn x:Name="DayColumn" Width="Auto" UniqueName="DayColumn" DataMemberBinding="{Binding Day}" Header="Day"   ShowColumnWhenGrouped="False">
                    <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                    <TextBlock Text="{Binding Day, Converter={StaticResource myLongDayConverter}}" />
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
        <telerik:GridViewDataColumn.GroupHeaderTemplate>
            <DataTemplate>                             
                    <TextBlock Text="{Binding Group.Key, Converter={StaticResource myLongDayConverter}}" />
            </DataTemplate>
        </telerik:GridViewDataColumn.GroupHeaderTemplate>
                    </telerik:GridViewDataColumn>                                      
                <telerik:GridViewDataColumn x:Name="StartTimeColumn"  DataMemberBinding="{Binding StartTime, Converter={StaticResource myTimeConverter}}" Header="Start" Width="SizeToHeader" />
                <telerik:GridViewDataColumn x:Name="EndTimeColumn" DataMemberBinding="{Binding EndTime, Converter={StaticResource myTimeConverter}}" Header="End" Width="SizeToHeader" />
                <telerik:GridViewDataColumn x:Name="DescriptionColumn" DataMemberBinding="{Binding Converter={StaticResource myDescriptionDisplayConverter}}" Header="Description" Width="250" />
                <telerik:GridViewDataColumn x:Name="PATotalColumn"  DataMemberBinding="{Binding PAtotal, Converter={StaticResource myTwoDPConverter}}" Header="PA" />
                </telerik:RadGridView.Columns>
    <!--telerik:RadGridView.GroupDescriptors>
        <telerik:ColumnGroupDescriptor Column="{Binding Columns[\DayColumn\], ElementName=dgdScheduled}" SortDirection="Ascending"  />
    </telerik:RadGridView.GroupDescriptors-->  
    <telerik:RadGridView.RowDetailsTemplate>
    <DataTemplate>
        <Border BorderBrush="{StaticResource BodyTextColorBrush}" BorderThickness="1" CornerRadius="2">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="10"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition Height="2"/>
                </Grid.RowDefinitions>
                <TextBlock Text="Category : " Grid.Row="0" Grid.Column="1"/>
                <TextBlock Text="Location : " Grid.Row="1" Grid.Column="1"/>
                <TextBlock Text="Provided by : " Grid.Row="2" Grid.Column="1"/>
                <TextBlock Text="Provided for : " Grid.Row="3" Grid.Column="1"/>
                <TextBlock x:Name="txtUnCategoryStringColumn"  Text="{Binding CategoryString}" Grid.Row="0" Grid.Column="2"/>
                <TextBlock x:Name="txtUnLocationStringColumn"  Text="{Binding Converter={StaticResource mySessionToLocationDisplayConverter}}" Grid.Row="1" Grid.Column="2"/>
                <TextBlock x:Name="txtUnServiceStringColumn"  Text="{Binding ServiceString}" Grid.Row="2" Grid.Column="2"/>
                <TextBlock x:Name="txtUnProvidedForStringColumn"  Text="{Binding ProvidedForString}" Grid.Row="3" Grid.Column="2"/>
            </Grid>
        </Border>
    </DataTemplate>
</telerik:RadGridView.RowDetailsTemplate>          
 
 
    </telerik:RadGridView>

One option may be to remove and then reapply the grouping as below, but I am unable remove the grouping
'get grouping
Dim colgroups As New Telerik.Windows.Data.GroupDescriptorCollection
 
For Each c As Telerik.Windows.Controls.GridView.ColumnGroupDescriptor In dgdScheduled.GroupDescriptors
    Dim temp As New Telerik.Windows.Controls.GridView.ColumnGroupDescriptor
    With temp
        .Column = c.Column
        .DisplayContent = c.DisplayContent
        .SortDirection = c.SortDirection
    End With
    colgroups.Add(temp)
Next
 
'remove grouping
For Each c In colgroups
    dgdScheduled.GroupDescriptors.Remove(c)
Next
 
'reapply datacontext
dgdScheduled.DataContext = From c As tblSession In Datastore.myJobPlanSessionsDDS.Sessions Where c.SessionType = CInt(1)
 
'reapply grouping
For Each c In colgroups
    dgdScheduled.GroupDescriptors.Add(c)
Next
 
dgdScheduled.ExpandAllGroups()
0
Accepted
Dimitrina
Telerik team
answered on 27 Apr 2012, 09:07 AM
Hello,

 I have tested the described scenario (changing the DataContext after the grouping is applied) with the Q1 Service Pack. I did not get such an error. 

Would you please try with the binaries from the latest internal build and let me know how it works? 

Regards,
Didie
the Telerik team

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

0
Jeremy
Top achievements
Rank 1
answered on 27 Apr 2012, 02:57 PM
That seems to have done the trick, but will do a little more testing and get back to you, thankyou
Tags
GridView
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Jeremy
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or