NullReference exception when clicking in a GridViewComboBoxColumn

2 posts, 0 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 28 May 2013 Link to this post

    Hi!

    I have a GridView declared as this:
    <telerik:RadGridView x:Name="DataGrid"
                             ItemsSource="{Binding Shifts, Source={StaticResource ViewModel}}"
                             SelectedItem="{Binding CurrentShift, Source={StaticResource ViewModel}, Mode=TwoWay}"
                             RowIndicatorVisibility="Collapsed" IsFilteringAllowed="False" ShowColumnFooters="False" ShowInsertRow="False"
                             ActionOnLostFocus="CommitEdit" EditTriggers="CellClick"
                             ValidatesOnDataErrors="None"
                             EnableRowVirtualization="False"
                             AutoGenerateColumns="False"
                             RowLoaded="DataGrid_RowLoaded" SelectionChanged="DataGrid_SelectionChanged" AddingNewDataItem="DataGrid_AddingNewDataItem" PreparingCellForEdit="DataGrid_PreparingCellForEdit" RowEditEnded="DataGrid_RowEditEnded">
                <telerik:RadGridView.Resources>
                    <Style TargetType="telerik:RadComboBox">
                        <Setter Property="Width" Value="148" />
                        <Setter Property="IsEditable" Value="True" />
                        <Setter Property="TextSearchMode" Value="Contains" />
                        <Setter Property="IsReadOnly" Value="True" />
                        <Setter Property="OpenDropDownOnFocus" Value="True" />
                    </Style>
                </telerik:RadGridView.Resources>
     
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Rast" Width="40" IsResizable="False">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <soe:SOECheckBox IsChecked="{Binding IsBreak, Mode=TwoWay}" Style="{StaticResource GridView_CheckBox}" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Från" DataMemberBinding="{Binding ActualStart}" Width="45" IsResizable="False">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ActualStart, Converter={StaticResource TimeConverter}}" TextAlignment="Right" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                        <telerik:GridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <soe:SOETextBox Text="{Binding ActualStart, Mode=TwoWay, Converter={StaticResource TimeConverter}}" IsTime="True" Width="44" TextAlignment="Right" TimeChanged="StartChanged" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellEditTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Till" DataMemberBinding="{Binding ActualEnd}" Width="45" IsResizable="False">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ActualEnd, Converter={StaticResource TimeConverter}}" TextAlignment="Right" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                        <telerik:GridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <soe:SOETextBox Text="{Binding ActualEnd, Mode=TwoWay, Converter={StaticResource TimeConverter}}" IsTime="True" Width="44" TextAlignment="Right" TimeChanged="EndChanged" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellEditTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Längd" Width="45" IsResizable="False" IsReadOnly="True">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Path=., Converter={StaticResource TimeScheduleShiftLengthConverter}}" TextAlignment="Right" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewComboBoxColumn Header="Passtyp" IsComboBoxEditable="True" DataMemberBinding="{Binding ShiftTypeId}" ItemsSource="{Binding Path=ShiftTypes, Source={StaticResource ViewModel}}" SelectedValueMemberPath="ShiftTypeId" DisplayMemberPath="Name" Width="150">
                        <telerik:GridViewComboBoxColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ShiftTypeName}" />
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellTemplate>
                        <telerik:GridViewComboBoxColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox SelectedValue="{Binding ShiftTypeId, Mode=TwoWay}" ItemsSource="{Binding Path=ShiftTypes, Source={StaticResource ViewModel}}" SelectedValuePath="ShiftTypeId" DisplayMemberPath="Name" SelectionChanged="ShiftType_SelectionChanged">
                                    <telerik:RadComboBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <VirtualizingStackPanel Width="250" />
                                        </ItemsPanelTemplate>
                                    </telerik:RadComboBox.ItemsPanel>
                                </telerik:RadComboBox>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellEditTemplate>
                    </telerik:GridViewComboBoxColumn>
                    <telerik:GridViewComboBoxColumn Header="Schematyp" IsComboBoxEditable="True" DataMemberBinding="{Binding TimeScheduleTypeId}" ItemsSource="{Binding Path=TimeScheduleTypes, Source={StaticResource ViewModel}}" SelectedValueMemberPath="TimeScheduleTypeId" DisplayMemberPath="Name" Width="150" IsVisible="{Binding ShowTimeScheduleType}">
                        <telerik:GridViewComboBoxColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding TimeScheduleTypeName}" />
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellTemplate>
                        <telerik:GridViewComboBoxColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox SelectedValue="{Binding TimeScheduleTypeId, Mode=TwoWay}" ItemsSource="{Binding Path=TimeScheduleTypes, Source={StaticResource ViewModel}}" SelectedValuePath="TimeScheduleTypeId" DisplayMemberPath="Name" SelectionChanged="TimeScheduleType_SelectionChanged">
                                    <telerik:RadComboBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <VirtualizingStackPanel Width="250" />
                                        </ItemsPanelTemplate>
                                    </telerik:RadComboBox.ItemsPanel>
                                </telerik:RadComboBox>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellEditTemplate>
                    </telerik:GridViewComboBoxColumn>
                    <telerik:GridViewComboBoxColumn Header="Anställd" IsComboBoxEditable="True" DataMemberBinding="{Binding EmployeeId}" ItemsSource="{Binding Path=Employees, Source={StaticResource ViewModel}}" SelectedValueMemberPath="Key" DisplayMemberPath="Value" Width="150" IsVisible="{Binding ShowEmployeeInGridView}">
                        <telerik:GridViewComboBoxColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding EmployeeName}" />
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellTemplate>
                        <telerik:GridViewComboBoxColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox SelectedValue="{Binding EmployeeId, Mode=TwoWay}" ItemsSource="{Binding Path=Employees, Source={StaticResource ViewModel}}" SelectedValuePath="Key" DisplayMemberPath="Value" SelectionChanged="Employee_SelectionChanged">
                                    <telerik:RadComboBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <VirtualizingStackPanel Width="250" />
                                        </ItemsPanelTemplate>
                                    </telerik:RadComboBox.ItemsPanel>
                                </telerik:RadComboBox>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellEditTemplate>
                    </telerik:GridViewComboBoxColumn>
                    <telerik:GridViewColumn Width="26" IsReadOnly="True" TabStopMode="Skip" IsResizable="False" IsVisible="{Binding IsReadOnly, ElementName=DataGrid, Converter={StaticResource BooleanInvertConverter}}">
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <soe:RadImageButton Style="{StaticResource GridViewDeleteRowButton}" Command="telerikGrid:RadGridViewCommands.Delete" CommandParameter="{Binding}" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

    As you can see there are three combobox columns and the first two works fine, but when I click or tab into the third (with Header="Anställd") I get the following exception:
    Object reference not set to an instance of an object.

       at Telerik.Windows.Controls.GridView.GridViewCell.SetCellElement()
       at Telerik.Windows.Controls.GridView.GridViewCell.HideEditor()
       at Telerik.Windows.Controls.GridView.GridViewCell.ToggleEditor()
       at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCellEditModeChanged(GridViewCell cell, Boolean newIsInEditMode)
       at Telerik.Windows.Controls.GridView.GridViewCell.IsInEditModeChanged(DependencyObject target, 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.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at Telerik.Windows.Controls.GridView.GridViewCell.set_IsInEditMode(Boolean value)
       at Telerik.Windows.Controls.GridView.GridViewCell.UpdateOnIsCurrentChanged(Boolean newValue)
       at Telerik.Windows.Controls.GridView.GridViewCell.IsCurrentChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
       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.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at Telerik.Windows.Controls.GridView.GridViewCell.set_IsCurrent(Boolean value)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.set_CurrentCellInfo(GridViewCellInfo value)
       at Telerik.Windows.Controls.GridView.GridViewCell.OnGotFocus(RoutedEventArgs e)
       at System.Windows.Controls.Control.OnGotFocus(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

    The exception is not handled anywhere and I end up in the Application_UnhandledException method in App.xaml.cs.
    I don't know where to look, the code worked before, but there must be some modification I have made, but I don't know where.
    Do you have any tip on where to start looking?

    Regards,
    Håkan


  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 31 May 2013 Link to this post

    Hi,
    Using only the xaml provided I was not able to reproduce the issue.
    May be you should check your DataGrid_PreparingCellForEdit event handler.

    If this does not help , I may need to perform a small debugging session over a runnable project.

    Regards,
    Pavel Pavlov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top