Home Forums WPF controls Xceed DataGrid for WPF How to get the content of a InsertionRow?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Xceed Support
    Member
    Post count: 5658
    #21716 |

    Hi,

    I am trying to find a way to get the content of the insertionRow, in the SelectedValue property we have the content of a dataRow. Is there something similar for the insertionRow?

    Thanks for your help.

    Imported from legacy forums. Posted by Simon (had 3543 views)

    Xceed Support
    Member
    Post count: 5658

    Unfortunately no.

    The “data item” behind the InsertionRow only gets created when the InsertionRow leaves edition.

    In addition, there is no way to retrieve the InsertionRow object itself other than by going through the VisualTree of the DataGridControl by yourself.

    There is always the DataGridControl.InitializingInsertionRow event, but this event only allow you to interact with the InsertionRow when it enters edition (before any values are entered by the user).

    You could always try to “preserve” a reference to the InsertionRow (after the event) and use it afterwards… But this is at your own risks since the InsertionRow can get disconnected whenever it is scrolled out of view ( UI Virtualization ).

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

    Xceed Support
    Member
    Post count: 5658

    I’m trying to get the content because after I edited a cell, I want to add new information to other cells depending the value of the first cell that I have edited( all in the insertionRow ). Do you have any ideas how should I proceed?

    Thanks in advance.

    Imported from legacy forums. Posted by Simon (had 254 views)

    Xceed Support
    Member
    Post count: 5658

    You could achieve what you want by overriding the InsertionRow and InsertionCell:

    <code>

    // —– InsertionRow

    public class CustomInsertionRow : InsertionRow
    {
    static CustomInsertionRow()
    {
    EventManager.RegisterClassHandler( typeof( CustomInsertionRow ), CustomInsertionCell.InsertionCellEndedEditEvent, new RoutedEventHandler( OnInsertionCellEndedEdit ) );
    }

    protected override Cell CreateCell( Column column )
    {
    return new CustomInsertionCell();
    }

    private static void OnInsertionCellEndedEdit( object sender, RoutedEventArgs e )
    {
    e.Source = sender;
    }

    }

    // —– InsertionCell

    public class CustomInsertionCell : InsertionCell
    {
    public static readonly RoutedEvent InsertionCellEndedEditEvent =
    EventManager.RegisterRoutedEvent( “InsertionCellEndedEdit”, RoutingStrategy.Bubble, typeof( RoutedEventHandler ), typeof( CustomInsertionCell ) );

    public CustomInsertionCell()
    {
    Binding ceb = new Binding(“ActualContent” );
    ceb.Source = this;

    BindingOperations.SetBinding( this, CustomInsertionCell.InsertionCellValueProperty, ceb );
    }

    #region InsertionCellValue Property

    public static readonly DependencyProperty InsertionCellValueProperty =
    DependencyProperty.Register( “InsertionCellValue”, typeof( object ), typeof( CustomInsertionCell ), new UIPropertyMetadata( null ) );

    public object InsertionCellValue
    {
    get
    {
    return ( object )this.GetValue( CustomInsertionCell.InsertionCellValueProperty );
    }
    set
    {
    this.SetValue( CustomInsertionCell.InsertionCellValueProperty, value );
    }
    }

    #endregion InsertionCellValue Property

    protected override void OnPropertyChanged( DependencyPropertyChangedEventArgs e )
    {
    base.OnPropertyChanged( e );

    if( e.Property == CustomInsertionCell.IsBeingEditedProperty )
    {
    if( ( bool )( e.NewValue ) == false )
    {
    this.RaiseEvent( new RoutedEventArgs( CustomInsertionCell.InsertionCellEndedEditEvent ) );
    }
    }
    }

    }
    </code>

    You can then register to the RoutedEvent in your application:

    <code>
    this.AddHandler( CustomInsertionCell.InsertionCellEndedEditEvent, new RoutedEventHandler( OnInsertionCellEndedEdit ) );
    </code>

    – The “Source” will be the InsertionRow
    – The “OriginalSource” will be the InsertionCell that was just edited.

    When you want to affect the value of the other cells, be sure to use the “InsertionCellValue” property, unless you wont be able to see/edit your newly set values…

    Finally, you want to use this DataTemplate instead for the InsertionRow:

    <code>
    <DataTemplate>
    <local:CustomInsertionRow/>
    </DataTemplate>
    </code>

    Note: This code is provided as an example only, it was not extensively tested…
    Note2: You might want to clean this up and maybe enhance it a little…

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

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