Welcome to the Xceed Community Sign in | Join | Help
Community Search  

EndEdit causes InvalidOperationException

Sort Posts: Previous Next
  •  03-25-2008, 6:39 PM Post no. 11310

    EndEdit causes InvalidOperationException

    The following statement:

    if (__myGrid.IsBeingEdited) __myGrid.EndEdit();

    Raises an exception:

    "An attempt was made to edit an item that is not part of the specified context."

    This occurs when I begin to type a value into the "New Row" of the grid, but then hit escape to cancel the new row, then hit the Close button on the form, which is wired to the above statement.

    My workaround is to call EndEdit on every DataRow in the source DataTable.

    I am using the 2.0 version of the DataGrid.

    Full exception below.

    Thanks!
    Brian

    {"An attempt was made to edit an item that is not part of the specified context."}
    [System.InvalidOperationException]: {"An attempt was made to edit an item that is not part of the specified context."}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    InnerException: null
    Message: "An attempt was made to edit an item that is not part of the specified context."
    Source: "Xceed.Wpf.DataGrid"
    StackTrace: " at Xceed.Wpf.DataGrid.DataGridControl.EndEditHelper(DataGridContext dataGridContext)
    at Xceed.Wpf.DataGrid.DataGridControl.EndEdit()
    at OnTrackWPF2.TimeEntryForm2.OnClosing(Object sender, CancelEventArgs e) in C:\_BjS\Projects\OnTrack\OnTrackWPF2\TimeEntryForm2.xaml.cs:line 283"
    TargetSite: {Void EndEditHelper(Xceed.Wpf.DataGrid.DataGridContext)}
  •  03-26-2008, 9:32 AM Post no. 11311 in reply to 11310

    Re: EndEdit causes InvalidOperationException

    Hi,

    Were you editing an InsertionRow that belongs to a detail or from the "master" data?

    If the InsertionRow was belonging to the "master" data, I'd like to have more details on your setup, as there seems to be a problem.

    If you were indeed editing a "detail" InsertionRow, then the exception is normal and to be expected. The suggested usage would be to use the DataGridControl.CurrentContext.EndEdit() to ensure that the appropirate DataGridControl gets invoked.


    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  03-26-2008, 1:59 PM Post no. 11312 in reply to 11311

    Re: EndEdit causes InvalidOperationException

    I believe there's only master data involved, as there's only one grid, although I tried __workLogGrid.CurrentContext.EndEdit() and received the same error. I've copied more details on the setup below.

    <b>Environment:</b> VS2008, + Resharper 4.0 Pre-Release (nightly builds).

    <b>Grid binding method, which is called after the form is loaded:</b>
    <color="#0000ff">
    public</color> <color="#0000ff">void </color> SetWorkLogSource(<color="#2b91af">DataView </color><color="#0000ff">value</color>) {
    _workLogSource = <color="#0000ff">new</color> <color="#2b91af"> DataGridCollectionViewSource</color> { Source = <color="#0000ff">value</color> };
    __workLogGrid.SetBinding(<color="#2b91af">ItemsControl</color>.ItemsSourceProperty, <color="#0000ff">new</color> <color="#2b91af">Binding</color> { Source = _workLogSource });
    }

    <b>Grid markup:</b>
    <color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">DataGridControl</color><color="#ff0000"> Margin</color><color="#0000ff">="21,162,21,20"</color> <color="#ff0000">x</color><color="#0000ff">:</color><color="#ff0000">Name</color><color="#0000ff">="__workLogGrid"</color> <color="#ff0000">AutoCreateColumns</color><color="#0000ff">="True"</color> <color="#ff0000"> HorizontalContentAlignment</color><color="#0000ff">="Stretch"</color> <color="#ff0000"> VerticalContentAlignment</color><color="#0000ff">="Top"</color> <color="#ff0000">SelectionMode</color><color="#0000ff">="Extended"</color> <color="#ff0000">NavigationBehavior</color><color="#0000ff">="RowOrCell"</color> <color="#ff0000"> CellEditorDisplayConditions</color><color="#0000ff">="None"</color> <color="#ff0000">EditTriggers</color><color="#0000ff">="BeginEditCommand, ClickOnCurrentCell, ActivationGesture"</color><color="#ff0000"> ItemScrollingBehavior</color><color="#0000ff">="Immediate"</color><color="#ff0000"> xcdg</color><color="#0000ff">:</color><color="#ff0000">GroupLevelIndicatorPane.ShowIndicators</color><color="#0000ff">="True"</color><color="#ff0000"> xcdg</color><color="#0000ff">:</color><color="#ff0000">GroupLevelIndicatorPane.ShowVerticalBorder</color><color="#0000ff">="True"></color>
    color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">DataGridControl.Resources</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">Style</color><color="#ff0000"> x</color><color="#0000ff">:</color><color="#ff0000">Key</color><color="#0000ff">="{</color><color="#a31515">x</color><color="#0000ff">:</color><color="#a31515">Type</color><color="#ff0000"> xcdg</color><color="#0000ff">:</color><color="#ff0000">ScrollTip</color><color="#0000ff">}"</color><color="#ff0000"> TargetType</color><color="#0000ff">="{</color><color="#a31515">x</color><color="#0000ff">:</color><color="#a31515">Type</color><color="#ff0000"> xcdg</color><color="#0000ff">:</color><color="#ff0000">ScrollTip</color><color="#0000ff">}"></color>
    <color="#0000ff"><</color><color="#a31515">Setter</color><color="#ff0000"> Property</color><color="#0000ff">="VerticalAlignment"</color><color="#ff0000"> Value</color><color="#0000ff">="Center" />
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">Setter</color><color="#ff0000"> Property</color><color="#0000ff">="HorizontalAlignment"</color><color="#ff0000"> Value</color><color="#0000ff">="Right" />
    </color><color="#a31515"></color><color="#0000ff"></</color><color="#a31515">Style</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"></</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">DataGridControl.Resources</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">DataGridControl.View</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">TableView</color><color="#ff0000"> UseDefaultHeadersFooters</color><color="#0000ff">="False"</color><color="#ff0000"> ShowFixedColumnSplitter</color><color="#0000ff">="False">
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">TableView.Theme</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">AeroNormalColorTheme</color><color="#0000ff"> />
    </color><color="#a31515"></color><color="#0000ff"></</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">TableView.Theme</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">TableView.FixedFooters</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">DataTemplate</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"><</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">InsertionRow</color><color="#0000ff"> />
    </color><color="#a31515"></color><color="#0000ff"></</color><color="#a31515">DataTemplate</color><color="#0000ff">>
    </color><color="#a31515"></color><color="#0000ff"></</color><color="#a31515">xcdg</color><color="#0000ff">:</color><color="#a31515">TableView.F
  •  03-26-2008, 2:16 PM Post no. 11313 in reply to 11312

    Re: EndEdit causes InvalidOperationException

    Thank you, we will take a look into this and report on our findings in this thread.
    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  03-31-2008, 12:15 PM Post no. 11314 in reply to 11313

    Re: EndEdit causes InvalidOperationException

    Hello,

    I just wanted to add that I am having this same issue when calling grid.EndEdit() while editing the insertion row.

    Thanks,
    Dan
  •  05-13-2008, 9:05 AM Post no. 12213 in reply to 11314

    Re: EndEdit causes InvalidOperationException

    Dan:
    Hello,

    I just wanted to add that I am having this same issue when calling grid.EndEdit() while editing the insertion row.

    Thanks,
    Dan

    Oh my... I'm having the same problem. Did anyone find a solution? 

  •  07-11-2008, 5:42 AM Post no. 13521 in reply to 12213

    Re: EndEdit causes InvalidOperationException

    *bump*
    Kiwi wannabe
  •  07-16-2008, 8:22 AM Post no. 13572 in reply to 13521

    Re: EndEdit causes InvalidOperationException

    My current solution:

     

    Get the InsertionRow from the Loaded-event:

    private InsertionRow m_InsertionRow;
    private void InsertionRowLoaded(object sender, RoutedEventArgs args)
    {
        m_InsertionRow = sender as CustomInsertionRow;
    }

     

    Call EndEdit separately on the InsertionRow:

                if (m_InsertionRow != null && m_InsertionRow.IsBeingEdited)
                {
                    try
                    {
                        m_InsertionRow.EndEdit();
                    }
                    catch (DataGridException)
                    {
                        return;
                    }
                } 


    Kiwi wannabe
    Filed under: ,
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.