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

NullReferenceException when editing

3 Answers 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pascal
Top achievements
Rank 1
Pascal asked on 15 Apr 2011, 02:34 PM
When using the GridView of the previous official release this worked correct! (2010 release)
Now i'm using the latest internal build (01219RadControls_for_Silverlight_4_2011_1_0411_DEV_hotfix)

Now with this release I get a NullReferenceException with the following stacktrace:

   at Telerik.Windows.Controls.GridViewBoundColumnBase.EvaluateIsReadOnlyState(Object item)
   at Telerik.Windows.Controls.GridViewBoundColumnBase.CanEdit(Object item)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginEdit(GridViewCell gridViewCell, RoutedEventArgs editingEventArgs)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCellMouseDown(GridViewCell cell, MouseButtonEventArgs args)
   at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

This customer also has the same problem, I guess:
http://www.telerik.com/community/forums/silverlight/gridview/data-sources-for-the-gridview-and-problems.aspx


I'm binding to a PagedCollectionView. Here is a part of the XAML:

                                                   <telerik:RadGridView Grid.Row="1" 
                                                                        ShowGroupPanel="False" 
                                                                        ItemsSource="{Binding Boekingen}" 
                                                                        AutoGenerateColumns="False" 
                                                                        RowIndicatorVisibility="Visible" 
                                                                        IsFilteringAllowed="False" 
                                                                        CanUserSortColumns="False" 
                                                                        ShowColumnFooters="True" 
                                                                        EditTriggers="Default" 
                                                                        IsReadOnlyBinding ="{Binding Path=DataContext.IsBoekingVerwerkt, ElementName=LayoutRoot}" 
                                                                        BeginningEdit="RadGridView_BeginningEdit">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="{Binding Path=Entity.BoekingBedrag, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Bedrag}" Width="120" IsSortable="False"  >
                                                               <telerik:GridViewDataColumn.CellTemplate>
                                                                   <DataTemplate>
                                                                       <Grid>
                                                                           <TextBlock x:Name="bedragNettoValutaMaskedTextBox" Text="{Binding Bedrag, Mode=TwoWay, Converter={StaticResource DecimalFormatConverter}, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}" HorizontalAlignment="Right"  />
                                                                           <TextBlock Margin="5,0,0,0" Text="{Binding Document.BedrijfValutaWeergave}" VerticalAlignment="Center" HorizontalAlignment="Left" />
                                                                       </Grid>
                                                                   </DataTemplate>
                                                               </telerik:GridViewDataColumn.CellTemplate>
                                                               <telerik:GridViewDataColumn.CellEditTemplate>
                                                                   <DataTemplate>
                                                                       <Grid>
                                                                           <telerik:RadMaskedTextBox x:Name="bedragNettoValutaMaskedTextBox" Culture="{Binding Culture, Source={StaticResource CurrentCulture}}" Value="{Binding Bedrag, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}" Style="{StaticResource RadNumericMaskedTextBox}"  />
                                                                           <TextBlock Margin="5,0,0,0" Text="{Binding Document.BedrijfValutaWeergave}" VerticalAlignment="Center" HorizontalAlignment="Left" />
                                                                       </Grid>
                                                                   </DataTemplate>
                                                               </telerik:GridViewDataColumn.CellEditTemplate>
                                                               <telerik:GridViewDataColumn.Footer>
                                                                   <StackPanel Orientation="Horizontal" Margin="5,0">
                                                                   </StackPanel>
                                                               </telerik:GridViewDataColumn.Footer>
                                                               <telerik:GridViewColumn.FooterCellStyle>
                                                                   <Style TargetType="telerik:GridViewFooterCell">
                                                                       <Setter Property="ContentTemplate">
                                                                           <Setter.Value>
                                                                               <DataTemplate>
                                                                                   <Grid Width="115">
                                                                                       <TextBlock Margin="0,0,5,0" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding DataContext.CurrentEntity.NogTeBoekenTotaalBedrag, ElementName=LayoutRoot, Converter={StaticResource DecimalFormatConverter}, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"/>
                                                                                       <TextBlock Margin="5,0,5,0" Text="{Binding DataContext.CurrentEntity.BedrijfValutaWeergave, ElementName=LayoutRoot}" VerticalAlignment="Center"/>
                                                                                   </Grid>
                                                                               </DataTemplate>
                                                                           </Setter.Value>
                                                                       </Setter>
                                                                   </Style>
                                                               </telerik:GridViewColumn.FooterCellStyle>
                                                           </telerik:GridViewDataColumn>

What is changed in the GridView that results in the exception?
How can I work around this?

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 15 Apr 2011, 04:25 PM
Hi Pascal,

Looking at your code, I would tell that you get this error because of the way you are binding the IsReadOnlyBinding in the Grid definition. The DataContext of the IsReadOnlyBinding is the current row and it should be bound to a bool property that belongs to this row. So, you should change it to: IsReadOnlyBinding="{Binding IsBoekingVerwerkt}" instead of IsReadOnlyBinding ="{Binding Path=DataContext.IsBoekingVerwerkt}.

Could you please try this change and if the problem still occurs, we are going to investigate it further.

All the best,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Pascal
Top achievements
Rank 1
answered on 15 Apr 2011, 09:17 PM
Thank you for your answer.

You say that the DataContext of the IsReadOnlyBinding is the current row
This is not true. This IsReadOnlyBinding is a property on the GridView, so it uses the datacontext of the gridview (or up), not of the row. (which row should it take than...)

But i deleted the property for a test and then editing is working as it should!
Now my Grid cannot be readonly when it should be. So i really need this functionality.

I'm 100% sure that the binding with the property is correct. Giving the code in the opening post.
With the 2010 version of Telerik this just worked!
So there must be something changed in the 2011 release.

Has this something to do with having a CellEditTemplate and using the property IsReadOnlyBinding ?:
http://www.telerik.com/community/forums/silverlight/gridview/please-please-don-t-change-isreadonlybinding-as-it-is-in-latest-internal-build.aspx

At this moment i have the problem that i cannot make my GridView with CellEditTemplates readonly.
0
Ivan Ivanov
Telerik team
answered on 19 Apr 2011, 01:55 PM
Hi Pascal,

It is extremely difficult for us to provide you the best support for you case, being given only your xaml. Would you please send us a demo version of your project so that we can debug it and give you an adequate solution. Meanwhile, you may place a converter in this binding and see if the expected value is being passed. Excuse us for the inconvenience.

Kind regards,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Pascal
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Pascal
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Share this question
or