Home Forums WPF controls Xceed DataGrid for WPF How to get ref to the InsertionRow?

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

    Given a DataGridControl, is there a way to get a reference to its InsertionRow?

    Or, given an InsertionRow, I can override EndInit or somesuch to get some code in there, but is there any way to get the DataGridControl it’s being created for?

    If it was just created once, I could exploit the timing locality between the creation of the two objects and snag a reference that way, but I’m assuming virtualization means old refs to InsertionRow may become invalid and new ones created at unpredictable times, so I need an on-the-fly solution.

    Imported from legacy forums. Posted by Russell (had 5180 views)

    Xceed Support
    Member
    Post count: 5658

    If you want to get a reference to the InsertionRow in the headers of a grid, you will need to handle the InsertionRow’s Loaded event and retrieve the reference there.

    To get a reference to an item’s parent DataGridControl, you can either get its DataGridContext and check the ParentDataGridControl property or you can use the GetParentDataGridControl attached property defined on the DataGridControl class.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 349 views)

    User (Old forums)
    Member
    Post count: 23064

    InsertionRow’s Loaded event – okay, how do you set this? There doesn’t seem to be a Loaded virtual method; one can do row.Loaded += … – but the code to do that, needs to be put somewhere else such as EndInit?

    InsertionRow doesn’t seem to have a DataGridContext member?

    Imported from legacy forums. Posted by Russell (had 569 views)

    Xceed Support
    Member
    Post count: 5658

    You can do it that way:

    <DataTemplate>
    <xcdg:InsertionRow Loaded=”MyLoadedHandler” />
    </DataTemplate>

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

    User (Old forums)
    Member
    Post count: 23064

    Right, that should work for the Loaded handler, thanks – I assume Loaded is called exactly once every time a new InsertionRow is created for a given data grid because of virtualization?

    That still leaves the problem of obtaining a handle to the InsertionRow from DataGridControl, or to the DataGridControl from InsertionRow – is there a way to do either of these things? InsertionRow doesn’t have a DataGridContext member, and as far as I can tell from a Google search, ParentDataGridControl is only a property of class Column.

    Imported from legacy forums. Posted by Russell (had 1234 views)

    User (Old forums)
    Member
    Post count: 23064

    Further investigation… according to:
    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Migrating_from_version_1.x.html

    Column.ParentDataGridControl no longer exists; the replacement is said to be DataGridControl.GetParentDataGridControl. But how is that a replacement? You can’t call it unless you already have the DataGridControl reference, in which case you don’t need to call it.

    Imported from legacy forums. Posted by Russell (had 695 views)

    Xceed Support
    Member
    Post count: 5658

    It is a static method 🙂

    Imported from legacy forums. Posted by Jenny [Xceed] (had 483 views)

    User (Old forums)
    Member
    Post count: 23064

    You’re right, so it is.

    void InsertionRow_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
    var grid = DataGridControl.GetParentDataGridControl(sender as DependencyObject);
    }

    And then I can store a reference to the InsertionRow in the original DataGridControl. Thanks!

    Imported from legacy forums. Posted by Russell (had 6186 views)

    User (Old forums)
    Member
    Post count: 23064

    As of version 3.6, GetParentDataGridControl was obsoleted so we now need to use:

     var grid = DataGridControl.GetDataGridContext(sender as
    DependencyObject).DataGridControl;

     -JLS

    Imported from legacy forums. Posted by Jeff (had 1187 views)

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