Home Forums WPF controls Xceed DataGrid for WPF EndEdit causes InvalidOperationException

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26514 |

    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)}

    Imported from legacy forums. Posted by Brian (had 4297 views)

    Xceed Support
    Member
    Post count: 5658

    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.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 433 views)

    User (Old forums)
    Member
    Post count: 23064

    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

    Imported from legacy forums. Posted by Brian (had 497 views)

    Xceed Support
    Member
    Post count: 5658

    Thank you, we will take a look into this and report on our findings in this thread.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 436 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello,

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

    Thanks,
    Dan

    Imported from legacy forums. Posted by Dan (had 3770 views)

    User (Old forums)
    Member
    Post count: 23064

    [quote user=”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[/quote]

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

    Imported from legacy forums. Posted by Alexander (had 866 views)

    User (Old forums)
    Member
    Post count: 23064

    *bump*

    Imported from legacy forums. Posted by Frances (had 607 views)

    User (Old forums)
    Member
    Post count: 23064

    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;
                    }
                } 

    Imported from legacy forums. Posted by Frances (had 2513 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.