Exception thrown trying to commit an empty row

Mar 30, 2009 at 3:24 AM
I get exception when I try to commit empty DataGrid row.

Exception calling "ShowDialog" with "0" argument(s): "Object reference not set to an instance of an object."

Steps to reproduce:

  • Goto "new row"
  • Press F2
  • Press ENTER

This works ok:

  • Goto "new row"
  • Press F2
  • Press ESC

As well as:

  • Goto "new row"
  • Press F2
  • Type "sdfdsf"
  • Press ENTER
Code is being called from powershell v2,..below is some of the code used:

add-type @"
    public class Person
    {
        public Person() {}

        public string First { get; set; }
        public string Last { get; set; }
    }
"@ -Language CsharpVersion3

#Creates an object of a generic type:
$people = New-GenericObject 'System.Collections.Generic.List' @('Person')
$form.Resources["people"] = $people

#
$form.ShowDialog()


<StackPanel>
    <dg:DataGrid ItemsSource="{DynamicResource people}" CanUserAddRows="True" AutoGenerateColumns="False">
      <dg:DataGrid.Columns>
             
        <dg:DataGridTextColumn Header="First" Binding="{Binding First}"></dg:DataGridTextColumn>
        <dg:DataGridTextColumn Header="Last" Binding="{Binding Last}"></dg:DataGridTextColumn>

      </dg:DataGrid.Columns>
    </dg:DataGrid>
  </StackPanel>

Any help would be appreciated!
Mar 30, 2009 at 3:30 PM
Edited Mar 30, 2009 at 4:19 PM
Using Trap does not seem to even catch it...seems the only solution is to never select a value if you don't need it...if blank it will throw an error (and my app crashes). Anyone have a hack or a solution?

You can find a link to the sample code here: http://cid-0dba2a6e137e8a9a.skydrive.live.com/self.aspx/Public/demo%7C%5F000.rar

Mar 31, 2009 at 3:10 AM
Some more details..and I found an issue almost the same thing: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361723

System.NullReferenceException: Object reference not set to an instance of an object.
   at MS
.Internal.Data.PropertyPathWorker.DetermineWhetherDBNullIsValid()
   at MS
.Internal.Data.PropertyPathWorker.get_IsDBNullValidForUpdate()
   at MS
.Internal.Data.ClrBindingWorker.get_IsDBNullValidForUpdate()
   at
System.Windows.Data.BindingExpression.ConvertProposedValue(Object value)
   at
System.Windows.Data.BindingExpressionBase.UpdateValue()
   at
System.Windows.Data.BindingExpression.Update(Boolean synchronous)
   at
System.Windows.Data.BindingExpression.UpdateSource()
   at
Microsoft.Windows.Controls.DataGridHelper.UpdateSource(FrameworkElement element, DependencyProperty dp)
   at
Microsoft.Windows.Controls.DataGridTextColumn.CommitCellEdit(FrameworkElement editingElement)
   at
Microsoft.Windows.Controls.DataGridColumn.CommitEdit(FrameworkElement editingElement)
   at
Microsoft.Windows.Controls.DataGridCell.CommitEdit()
   at
Microsoft.Windows.Controls.DataGrid.OnExecutedCommitEdit(ExecutedRoutedEventArgs e)
   at
Microsoft.Windows.Controls.DataGrid.OnExecutedCommitEdit(Object sender, ExecutedRoutedEventArgs e)
   at
System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at
System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
   at
System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at
System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at
System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at
System.Windows.UIElement.OnExecutedThunk(Object sender, ExecutedRoutedEventArgs e)
   at
System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
   at
System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at
System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at
System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at
System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at
System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at
System.Windows.Input.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated)
   at
System.Windows.Input.RoutedCommand.Execute(Object parameter, IInputElement target)
   at
Microsoft.Windows.Controls.DataGrid.EndEdit(RoutedCommand command, DataGridCell cellContainer, DataGridEditingUnit editingUnit, Boolean exitEditMode)
   at
Microsoft.Windows.Controls.DataGrid.CommitEdit(DataGridEditingUnit editingUnit, Boolean exitEditingMode)
   at
Microsoft.Windows.Controls.DataGrid.CommitAnyEdit()
   at
Microsoft.Windows.Controls.DataGrid.OnEnterKeyDown(KeyEventArgs e)
   at
Microsoft.Windows.Controls.DataGrid.OnKeyDown(KeyEventArgs e)
   at
System.Windows.UIElement.OnKeyDownThunk(Object sender, KeyEventArgs e)
   at
System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at
System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at
System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at
System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at
System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at
System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at
System.Windows.Input.InputManager.ProcessStagingArea()
   at
System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at
System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at
System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
   at
System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at
System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at
System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at
System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
   at
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
Exception calling "Run" with "1" argument(s): "Object reference not set to an instance of an object."