Welcome to the Xceed Community | Help
Community Search  

InitializingInsertionRow does not fire

Sort Posts: Previous Next
  •  07-07-2008, 12:43 AM Post no. 13445

    InitializingInsertionRow does not fire

    Hi All,

    Under what circumstances would InitializingInsertionRow not fire? My scenario is outlined below: 

    Here's the grid:

      <DataGrid:DataGridControl DockPanel.Dock="Bottom" x:Name="FundProductCalculationTypeGrid"
                                AutoCreateDetailConfigurations="False"
                                NavigationBehavior="RowOrCell"
                                ItemsSource="{Binding Path=FrameworkSelections}"
                                ReadOnly="False"
                                ItemScrollingBehavior="Immediate" d:LayoutOverrides="GridBox" Margin="8,57,19,131" Grid.Column="1"
                                InitializingInsertionRow="FundProductCalculationTypeGrid_OnInitializingInsertionRow" >
              <DataGrid:DataGridControl.View>
                <Views:TableView>             
                  <Views:TableView.Theme>
                    <Views:AeroNormalColorTheme/>
                  </Views:TableView.Theme>
                </Views:TableView>
              </DataGrid:DataGridControl.View>
            </DataGrid:DataGridControl>
             <Button x:Name="AddButton" Click="AddButton_OnClick"  RenderTransformOrigin="-1.535,-0.085" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="Add" Grid.Column="1" Margin="8,0,0,96.723" d:LayoutOverrides="Height" Width="60.083"/>

     The datasource "FrameworkSelections" is a BindingList<T> 

     

     Here's: AddButton_OnClick

     

    private void AddButton_OnClick(object sender, RoutedEventArgs e)
            {
                IBindingList bindingList = FundProductCalculationTypeGrid.ItemsSource as IBindingList;
                if (bindingList != null)
                {               
                    object newItem = bindingList.AddNew();
                    FundProductCalculationTypeGrid.BeginEdit(newItem);
                }
            }

     

    Here's FundProductCalculationTypeGrid_OnInitializingInsertionRow which never gets invoked:

     

      private void FundProductCalculationTypeGrid_OnInitializingInsertionRow(object sender, InitializingInsertionRowEventArgs e)
            {
                e.InsertionRow = new ProductFundFrameworkEntryInsertionRow(); //NEVER GETS INVOKED
            }

     

    Is it something to do with the way I'm adding adding items to the underlying list? If so, how should I go about it?

    I've tried assigning the event handler in both code and Xaml and neither has any effect.

     Any help would be appreciated.

  •  07-07-2008, 1:18 AM Post no. 13446 in reply to 13445

    Re: InitializingInsertionRow does not fire

    Update to my own post...

    Adding the following Xaml causes the event to fire, but means there is *always* an InsertionRow sitting there as the last row in the grid, where as I only want it on demand.

     <Views:TableView.Footers>
            <DataTemplate>
                <InitialMargin:ProductFundFrameworkEntryInsertionRow />
            </DataTemplate>
     </Views:TableView.Footers>

    What I'm trying to achieve is to be able to:

    1) Click Add

    2) See a new insertion row in edit mode with focus

    3) Override the behavior when that row is comitted (EndEdit) to say, write an update to a back-end source/service

    Where am I going wrong?

  •  07-08-2008, 9:17 AM Post no. 13461 in reply to 13446

    Re: InitializingInsertionRow does not fire

    Hi Steve,

     Calling AddNew on your BindingList, if you are not using a DataGridCollectionView, will add the item right away to the list.

       This new item will have a container generated and will appear in the DataGridControl.  Since this is a DataRow and not an InsertionRow, you won't have the InitializingInsertionRow event triggered.

     In fact, this event is only triggered when entering edition on an InsertionRow itself and is meant to initialize data without flagging the row as "dirty", giving the user the possibility to end edition of the insertion row without inserting the underlyng item he did not modify anything.

     

    As you mentioned in your last reply, you should use an InsertionRow.  However, it will always be part of the DataGridControl. 

    What you could try is to style your InsertionRow and set its Visible property to false.  Then, you could use a trigger that reacts on the InsertionRow's IsBeingEdited property.  When it becomes True, you could set the Visible property to true.

     Your add button could then simply call BeginEdit on the InsertionRow.

     As of comitting to the back-end, you could have a hard time doing so with the current version of the DataGridControl.  You could use the InsertionRow's IsVisibleChanged event and commit when it becomes invisible.

    We will provide easier way to intervene in the edition model in the following version of Xceed DataGrid for WPF with routed events and virtual methods.

     

    Regards,

     Pierre-Luc


    Pierre-Luc Ledoux
    Software Developer
    Xceed Software Inc.
  •  07-16-2008, 2:19 PM Post no. 13579 in reply to 13461

    Re: InitializingInsertionRow does not fire

    " Your add button could then simply call BeginEdit on the InsertionRow."

     How can one do that ? How can I get a reference to the InsertionRow from the code ?

     

    I want to have insertion row always displayed in the header and I want it to have different control templates applied to each column from it. The only way I was able to do that was in the InitializingInsertionRow event (e.InsertionRow)....But this is not good, because that event fires only when editing the insertion row and I want to "see" the insertion row with the templates applied from the begining.

     If I could access the InsertionRow , I could load the templates whenever I wanted, not only on the InitializingInsertionRow event.

    Or, is it possible to provide the Control Templates in the InsertionRow style for each column ? Can someone please post an example ?

     

     

  •  07-17-2008, 6:36 AM Post no. 13589 in reply to 13579

    Re: InitializingInsertionRow does not fire

    XAML

    <xceed:TableView UseDefaultHeadersFooters="False">
         <DataTemplate>
              <xceed:InsertionRow Loaded="InsertionRowLoaded"/>
         </DataTemplate>
         </xceed:TableView.FixedHeaders>
    </xceed:TableView>

    C#

    private InsertionRow m_InsertionRow;

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


    Kiwi wannabe
    Filed under: ,
  •  07-17-2008, 4:35 PM Post no. 13602 in reply to 13589

    Re: InitializingInsertionRow does not fire

    thank you for your answer.

    Unfortunatelly, this does not help me. I'm loading the DataSource of the grid on a button click and also creating the insertionrow at that time:

     Style sty = (Style)FindResource("insertionrow_style");
      template = new DataTemplate();
      FrameworkElementFactory insertionRowFactory = new FrameworkElementFactory(typeof(InsertionRow));
      insertionRowFactory.SetValue(InsertionRow.StyleProperty, sty);
      template.VisualTree = insertionRowFactory;
      grid.View.FixedHeaders.Add(template);

     If I use the DataTemplate in the XAML as you suggested, then the Loaded event is called when the window first loads and the InsertionRow defined there has no Cells yet so I dont know how to provide the templates.

    I'm adding the InsertionRow later as you can see from the above code and here I dont know how to add a Loaded event or how to access the InsertionRow after that.

     Thanks in advance,


  •  07-18-2008, 3:03 AM Post no. 13610 in reply to 13602

    Re: InitializingInsertionRow does not fire

    Hi Dani,

    try adding the event to your Style?

             <Style TargetType="{x:Type xceed:InsertionRow}" x:Key="insertionrow_style">
                <EventSetter Event="Loaded" Handler="InsertionRowLoaded" />
            </Style>


    Kiwi wannabe
    Filed under: , ,
  •  07-20-2008, 2:08 AM Post no. 13638 in reply to 13610

    Re: InitializingInsertionRow does not fire

    Thanks Frances, you are a life saver. I've tried 100 solution but I missed this one.

    Now I can apply all the templates I want in the InsertionRow cells. It looks and works really nice.

  •  07-20-2008, 3:19 PM Post no. 13641 in reply to 13638

    Re: InitializingInsertionRow does not fire

    One more thing...

     Im having trouble using a template for one cell of the InsertionRow. Im using a Button template for one column, a ComboBox for another and default editor for string in the others.

    I manage to make the button work as intended, but im having trouble with the ComboBox column. When the data is loaded and the InsertionRow is first displayed I can see the values in the combobox (just a simple bound string[]) and I can select one of them.

    But doing this does not set the InsertionRow in EditMode, so IsBeingEdit is false. That means the EndEdit wont do anything. I wonder if you only have combo boxes in the InsertionRow....how can you save the data ?

    Clicking in a defalt string editor, puts the InsertionRow into edit mode and it clears the selected data from the combobox and even its ItemsSource.

    This behaviour kinda makes the combobox from the InsertionRow useless. Any ideea how can I still use the ComboBox in the InsertionRow ?

  •  07-21-2008, 3:47 AM Post no. 13650 in reply to 13641

    Re: InitializingInsertionRow does not fire

    Well, this is how I do it:

            <xceed:CellEditor x:Key="categoryEditor">
                <xceed:CellEditor.EditTemplate>
                    <DataTemplate>
                        <ComboBox BorderThickness="0" VerticalContentAlignment="Top" ItemsSource="{Binding ElementName=m_MyPage, Path=Categories}" SelectedValue="{xceed:CellEditorBinding}" />
                    </DataTemplate>
                </xceed:CellEditor.EditTemplate>
                <xceed:CellEditor.ActivationGestures>
                    <xceed:KeyActivationGesture Key="F2"/>
                    <xceed:KeyActivationGesture Key="Space"/>
                </xceed:CellEditor.ActivationGestures>
            </xceed:CellEditor>

     

    Where 'm_MyPage' is the name of the Page, and 'Categories' is a Collection<string>.


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