Home Forums WPF controls Xceed DataGrid for WPF Hitting "Enter" in the insertion row calls CancelingNewItem rather than CommittingNewItem

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

    Hey. I’m having trouble setting up the most basic implementation of an editable datagrid. I followed example 1 on the documentation page: http://doc.xceedsoft.com/products/xceedwpfdatagrid/Inserting_Data.html.

     I implemented the 3 main events, and they appear to work fine, except that when I’m editing an Insertion row and hit “Enter”, CancelingNewItem gets called. What’s strange is that there’s no validation errors happening – if instead of hitting error I simply click on another row, then CommittingNewItem gets called, as it should.

     What could be causing this? I’m not intercepting any key down events or anything, the grid is doing it all on its own. Here’s the code from my implementation:

            private void DataGridCollectionViewSource_CreatingNewItem(object sender, DataGridCreatingNewItemEventArgs e)
            {
                IEnumerable SourceCollection = e.CollectionView.SourceCollection;
                e.Handled = true;
                if( SourceCollection is List<Person>)
                    e.NewItem = new Person();
                else if( SourceCollection is List<Place>)
                    e.NewItem = new Place();
                else if( SourceCollection is List<Thing>)
                    e.NewItem = new Thing();
                else
                    e.Handled = false;
            }
            private void DataGridCollectionViewSource_CommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e)
            {
                IList SourceCollection = (IList)e.CollectionView.SourceCollection;
                SourceCollection.Add(e.Item);
                e.Index = SourceCollection.Count - 1;
                e.NewCount = SourceCollection.Count;
                e.Handled = true;
            }
            private void DataGridCollectionViewSource_CancelingNewItem(object sender, DataGridItemHandledEventArgs e)
            {
                // Manually handling the insertion of new items requires that the CreatingNewItem,
                // CommitingNewItem, and CancelingNewItem events must all be handled even if nothing
                // is done in the event.
                e.Handled = true;
            }
    
    And my xaml:
    
            <style x:key="DefaultXceedGrid" targettype="{x:Type xcdg:DataGridControl}">
                <Setter Property="EditTriggers" Value="SingleClick,CellIsCurrent,RowIsCurrent"/>
                <Setter Property="ValidationMode" Value="CellEndingEdit"/>
                <Setter Property="CellEditorDisplayConditions" Value="MouseOverCell"/>
                <Setter Property="SelectionMode" Value="Single"/>
                <Setter Property="NavigationBehavior" Value="CellOnly"/>
                <Setter Property="UpdateSourceTrigger" Value="CellContentChanged"/>
                <Setter Property="ItemScrollingBehavior" Value="Immediate"/>
                <Setter Property="CellErrorStyle" Value="{StaticResource xcdgErrorStyle}"/>
            </style>
    
            <xcdg:datagridcollectionviewsource x:key="PeopleView" source="{Binding Path=People}" creatingnewitem="DataGridCollectionViewSource_CreatingNewItem" committingnewitem="DataGridCollectionViewSource_CommittingNewItem" cancelingnewitem="DataGridCollectionViewSource_CancelingNewItem">
                <xcdg:datagridcollectionviewsource.itemproperties>
                    <xcdg:datagriditemproperty name="Title" title="Title">
                    ...
                </xcdg:datagriditemproperty></xcdg:datagridcollectionviewsource.itemproperties>
            </xcdg:datagridcollectionviewsource>
    
            <xcdg:DataGridControl x:Name="LayersGrid" Grid.Row="0"
                                  Style="{StaticResource DefaultXceedGrid}"
                                  ItemsSource="{Binding Source={StaticResource PeopleView}}"
                                  AutoCreateColumns="False">
                <xcdg:DataGridControl.Columns>
                    <xcdg:Column FieldName="Title" Title="Title" VisiblePosition="0" Visible="True" MinWidth="65" MaxWidth="100" IsMainColumn="True" />
                    ...
                </xcdg:DataGridControl.Columns>
                <xcdg:DataGridControl.View >
                    <xcdg:TableView ShowFixedColumnSplitter="False" ShowRowSelectorPane="False" 
                                    UseDefaultHeadersFooters="False" FixedColumnCount="1">
                        <xcdg:TableView.FixedHeaders>
                            <DataTemplate>
                                <xcdg:ColumnManagerRow AllowSort="False" AllowColumnReorder="False" AllowAutoFilter="False" />
                            </DataTemplate>
                        </xcdg:TableView.FixedHeaders>
                        <xcdg:TableView.Footers>
                            <DataTemplate>
                                <xcdg:InsertionRow InsertionMode="Continuous" />
                            </DataTemplate>
                        </xcdg:TableView.Footers>
                        <xcdg:TableView.Theme>
                            <xcdg:AeroNormalColorTheme />
                        </xcdg:TableView.Theme>
                    </xcdg:TableView>
                </xcdg:DataGridControl.View>
            ...
            </xcdg:DataGridControl>

     If it’s relevant, I have InsertionMode = Continuous set on my Insertion Row, so I expect hitting enter to commit the current row and start on a new insertion row.

     

    Update

    This screenshot should adequately demonstrate that without any interference from my own code, the Xceed libraries are suddenly deciding to cancel the edit rather than commit it, and I have no idea why:

     Strack Trace when user hits "Enter"

     

    Here’s the stack trace when I instead click a different row, which results in the row getting properly inserted:

     When clicking another row

    Imported from legacy forums. Posted by Insight (had 719 views)

    User (Old forums)
    Member
    Post count: 23064

    One thing I forgot to mention, I’m using Xceed 4.3.12074.17240

     

    I was trying to figure out why the grid is cancelling the new item when I hit enter, and it looks like it’s because the grid thinks nothing’s changed. I discovered this by putting a break point on the converter on the cell editor template to see if it was getting fired, and it was, but it was getting fired with the old cell value.

     

    So if I set the default object (using the CreatingNewItem event) to have a property with the value “1000”, and then when I edit the row, I change that to “1234” and hit “Enter”, the converter’s ConvertBack gets called with the value  “1000” – which means the AutoSelectTextBox isn’t passing the correct value (it’s current content) back to the source binding. This is my controlTemplate:

            <xcdg:CellEditor.EditTemplate>
                <DataTemplate>
                    <xcdg:AutoSelectTextBox Style=”{StaticResource DefaultAutoSelectTextBox}”
                                            Text=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=xcdg:DataCell}, Path=Content,  UpdateSourceTrigger=LostFocus,
                                            Converter={StaticResource PercentageFormatConverter}, ConverterParameter={StaticResource PercentageFormatString}}” />
                </DataTemplate>
            </xcdg:CellEditor.EditTemplate>

     

    The unorthodox binding path is necessary because Xceed’s default CellEditorBinding fires on every keystroke (UpdateSourceTrigger=PropertyChanged) – with no option to change that behavior, so I read that this is the only workaround to prevent your converter from prematurely firing on every keystroke and messing with the user’s input.

    I can confirm that if I change this UpdateSourceTrigger back to “PropertyChanged”, the insertion row works correctly when the user hits “Enter” – but then a whole other world of problems arise as a result of the value getting updated on every keystroke.

     

    I’m at am impasse here. Why does Xceed’s insertion row require the cell editor’s UpdateSourceTrigger to be PropertyChanged to work correctly? Is this possibly an overlooked logical error in the way your insertion rows are implemented?

    Imported from legacy forums. Posted by Insight (had 859 views)

    parrjohn
    Participant
    Post count: 1

    I am currently experiencing the same problem. Has this since been addressed per chance? I currently cannot find any way round this.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.