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

RowNotInTableException with DataTable binding

6 Answers 597 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 20 Dec 2011, 10:10 PM
After adding or removing rows from a DataTable, clicking on a row throws a RowNotInTableException.

I can perform other actions such as selecting the row using the row selector checkbox, but if I click on the row anywhere outside the checkbox, I get the error (looks like its on the cell mouse down event).

The error sometimes doesn't get thrown but usually does (threading issue?).

System.Data.RowNotInTableException was unhandled by user code
  Message=This row has been removed from a table and does not have any data.  BeginEdit() will allow creation of new data in this row.
  Source=System.Data
  StackTrace:
       at System.Data.DataRow.GetDefaultRecord()
       at System.Data.DataRow.get_Item(String columnName)
       at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName)
       at lambda_method(Closure , DataRow )
       at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Extensions\FuncExtensions.cs:line 24
       at Telerik.Windows.Data.QueryableCollectionViewGroup.FindLastLevelGroupByItem(Object item) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Grouping\QueryableCollectionViewGroup.cs:line 536
       at Telerik.Windows.Controls.GridView.GridViewDataControl.GetRowForItem(Object item, Boolean forceGroupExpand) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:line 3226
       at Telerik.Windows.Controls.GridView.GridViewDataControl.get_CurrentCell() in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:line 764
       at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 404
       at System.Windows.UIElement.OnMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.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.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.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.RaiseTrustedEvent(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.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
  InnerException:

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 21 Dec 2011, 11:10 AM
Hi Andrew,

 We have investigated such a scenario. This seems to be a problem with the DataTable specifics. Please refer to this msdn article.

Best wishes,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Andrew
Top achievements
Rank 1
answered on 21 Dec 2011, 03:23 PM
Also, we didn't have the problem when using Q2 2010 but now that we are using Q3 2011

Also, the error is thrown when clicking on any row in the gridview.

0
Dimitrina
Telerik team
answered on 21 Dec 2011, 04:18 PM
Hi Andrew,

 If this behaviour was working previously, could you please send us a small running project? That way we could further investigate what is wrong.

Best wishes,
Didie
the Telerik team

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

0
Andrew
Top achievements
Rank 1
answered on 21 Dec 2011, 07:48 PM
We've submitted a support ticket #495205 with a code sample.
0
Dimitrina
Telerik team
answered on 22 Dec 2011, 09:05 AM
Hi,

 Thank you for submitting a sample project. Please keep the further communication in the support ticket.

All the best,
Didie
the Telerik team

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

0
Andrew
Top achievements
Rank 1
answered on 03 Jan 2012, 04:58 PM
For the sake of others, the short answer is to make sure that if you want the user to select an item from the grid that will be removed at some point, be sure to set the selected item to null before removing the row from the datatable. You should need a temporary variable to store the reference to the selected item so that you can use the value after you set the selection to null.

private void DoRemove()
{
    DataRowView selectedRow = SelectedPersonView;
    SelectedPersonView = null;
    Persons.Rows.Remove(selectedRow.Row);
}

Also might have to set grid.CurrentColumn = null if after you clear row selection you still see a box around a cell as if a cell is ready to be selected.
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or